AnantLabs / ocupload

Automatically exported from code.google.com/p/ocupload
0 stars 0 forks source link

In Internet Explorer 8 the additionals params override those of the form #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Html :

<form action="http://www.soludedia.fr" method="post">
<input type="hidden" name="var1" value="AAAA">
<div id="jq-parcourir-liste"></div><span id="jq-parcourir">File</span>
<input type="submit" value="Send" id=jq-envoi-msg>
</form>

Js :

var upload = $('#jq-parcourir').upload( {
    autoSubmit: false,
    action: "http://www.soludedia.fr",
    params: {var1: "BBBB"},
    onSelect: function() {
        $('#jq-parcourir-txt').html('');
        this.submit();
    },
    onComplete: function(response) {

        if(response.length <= 0) return;

        response = eval("(" + response + ")");
        if(response.error && response.error.length > 0)
            alert(response.error);
        else{
            $('#jq-parcourir-liste').append(response.file);
        }
    }
});

What is the expected output? What do you see instead?
After submission of the form BBBB is received instead of AAAA

To fix it, line 237, in :

submit: function() { [...]
    iframe.unbind().load(function() {

add this line before "self.onComplete(response);":

$(form).remove();

Original issue reported on code.google.com by cont...@soludedia.fr on 4 Oct 2010 at 11:08

GoogleCodeExporter commented 9 years ago
or better: to use it several times, add a class to the imputs "options.params" :

submit: function() {
    // Do something before we upload
    this.onSubmit();
    // add additional paramters before sending
    $.each(options.params, function(key, value) {
        form.append($(
            '<input '+
                'type="hidden" '+
                'name="'+key+'" '+
                'value="'+value+'" '+
                'class="jq-ocupload-inputs" '+ // fix here
            '/>'
        ));
    });

    // Submit the actual form.
    // In that way, because we don't want jquery events (it fires submit event for other parent form)
    form.get(0).submit();

    // Do something after we are finished uploading
    iframe.unbind().load(function() {
        // Get a response from the server in plain text
        var myFrame = document.getElementById(iframe.attr('name'));
        var response = $(myFrame.contentWindow.document.body).text();

        // fix here
        $(form).children("input.jq-ocupload-inputs").remove();

        // Do something on complete
        self.onComplete(response); //done :D
    });
}

Original comment by cont...@soludedia.fr on 4 Oct 2010 at 3:24