I have problem with Internet Explorer
Here is a sample of script with AJAX and jQuery and works fine in other browsers but in IE
it doesn't
index.html
<form enctype="multipart/form-data" method="post">
<input name="file" type="file" multiple="true" id="file" />
<input type="button" value="Upload" /> or clic "U"
</form>
ajax.js
$(':button').click(function(){
var formData = new FormData($('form')[0]);
$("#data").html(formData);
$.ajax({
url: 'upload.php', //server script to process data
type: 'POST',
xhr: function() { // custom xhr
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
}
return myXhr;
},
//Ajax events
//beforeSend: beforeSendHandler,
success: function(html) {
$("#php").html(html);
$("#file").val('');
},
error:function(html) {
$("#php").html(html);
},
enctype: 'multipart/form-data',
// Form data
data: formData,
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
});
});
Works fine in other browsers but in Opera
and IE
it is not working.
This is the CONSOLE( F12
) erron on IE
SCRIPT5009: 'FormData' is undefined
ajax.js, line 53 character 9
What should I do to solve the problem?
SCRIPT5009: 'FormData' is undefined ajax.js, line 53 character 9 this is the code
Assuming your error lies here, move your method for FormData
above the code you posted above.
Example:
function FormData (form) {
....
}
$(':button').click(function(){
var formData = new FormData($('form')[0]);
$("#data").html(formData);
$.ajax({
url: 'upload.php', //server script to process data
type: 'POST'...
EDIT
Apparently, FormData
is not supported in IE. You may, however, be able to use jQuery's serialize
like so:
var formData = $('form').serialize();
FormData class is only available for html 5 and html5 is supported on the latest version of the browser.
the problem is for IE even the latest has some security issue for uploading multiple files through ajax but u can upload one file.
if u insist uploading with ajax its better to use iframe or flash object to upload in the old browsers
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.