![](/img/trans.png)
[英]jQuery not working on IE11 but working on Chrome, Firefox and Edge?
[英]Ajax Jquery File Uploader not working in IE11 & Microsoft Edge
我有ajax jquery文件上傳器,它在Chrome,Firefox中可以正常工作,但在IE和Microsoft Edge上不起作用。 它沒有給我任何回應,我嘗試了所有可能的解決方案,但仍然無法正常工作。
這是我的JS:
$('form').on('submit', function(event) {
event.stopPropagation();
event.preventDefault();
$.ajax({
url: 'upload.php',
type: 'POST',
data: new FormData(this),
cache: false,
dataType: 'json',
processData: false,
contentType: false,
success: function(data, textStatus, jqXHR)
{
console.log(data)
},
error: function(jqXHR, textStatus, errorThrown)
{
console.log('ERRORS: ' + textStatus);
}
});
});
和我的表格:
<form method="post" enctype="multipart/form-data">
<input name="file[]" type="file" required multiple />
<input type="radio" name="something" value="1"> 1
<input type="radio" name="something" value="2"> 2
</form>
怎么解決!!
我覺得問題出在您向ajax
分配data
的方式上。 當您在new FormData
說this
句話時,它實際上是通過ajax call
而不是form
引用的。 因此,最好將該概念保留在外部,然后按如下所示重試。
$('form').on('submit', function(event) {
//event.stopPropagation();//I don't think this is necessary
event.preventDefault();
var formdata=new FormData($('form').get(0)) //try with this here
$.ajax({
url: 'upload.php',
type: 'POST',
data: formdata,
cache: false,
dataType: 'json',
processData: false,
contentType: false,
success: function(data, textStatus, jqXHR)
{
console.log(data)
},
error: function(jqXHR, textStatus, errorThrown)
{
console.log('ERRORS: ' + textStatus);
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.