天天看点

ajax提交enctype=,javascript - how to submit Form with AJAX Using enctype="multipart/form-data"? - Stac...

Here's a way that works even with IE8 and above:

Use malsup's jquery form plugin, which will take care of both XHR as well as the hidden iframe that IE needs for ajax upload.

Code snippet here:

.

.

.

$(document).ready(function()

{

var options = {

cache:'false', //IE FIX

data: $('#formid').serialize(),

dataType: 'json',

processData: false,

contentType: false,

success: function(data)

{

//success action

},

error: function(XMLHttpRequest, textStatus, errorThrown)

{

//error action

}

};

$('#formid').ajaxForm(options);

});