简体   繁体   中英

Ajax file upload using formdata Internet Explorer 10

I've been looking for a solution but never succeeded. I have a ajax call with formdata for an image to upload to server. The code looks like

$.ajax({

    type:'POST',

    url:'url',

    data:UPLOAD_DATA,

    processData:false,

    contentType:false,

    cache:false,

    timeout:10000,

    mimeType:'multipart/form-data',

    dataType:'json',

    success:function(data){

        if(data.success){

            alert(data.success);

        }else if(data.redirect){

        window.location.redirect=data.redirect;

        }else{

            alert(JSON.stringify(data));

        }

    }

});

While sending the console remains at showing "pending". This code works in all the browser except ie10

please help me..

Previous IE version (8 and previous) were not accepting a JSON response to the ajax submit of a multipart form. Thus resulting in never going into the success callback, and in some situations suggesting the user to download the JSON response as a text file.

I suppose IE10 is not making the same mistake. If it does, you might consider returning the JSON content as text, set request dataType to text, and parse the text response back to JSON client side in the success callback.

However, before searching for headaches, please have a look at jQuery Form plugin which will handle the ajax submit of a form (multipart or not) and provide callbacks like the usefull uploadProgress one.

Iam sorry it was a silly mistake. I think the url as relative path in the server doesnt support in internet explorer, by giving full https://" ... " path solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM