[英]Jquery ajax call on IOS return status 400
I'm trying to submit form with files with the following call : 我正在尝试通过以下调用提交包含文件的表单:
var formData = new FormData(this);
$.ajax({
cache: false,
processData: false,
contentType: false,
data: formData,
type: "POST",
url: "api/action",
success: function (msg) {
console.log(msg);
},
error: function (msg) {
console.log(msg);
}
});
it works fine in web browser including safari it works fine in android OS 它在包括safari在内的网络浏览器中运行良好,在android OS中运行良好
but in IOS the call failed and return error 400 但在IOS中,调用失败并返回错误400
var $form = $(this); // <- change this depending on your scope/usecase
$form.find('input[name][type!="file"], select[name], textarea[name]').each(function(i, e) {
if ($(e).attr('type') == 'checkbox' || $(e).attr('type') == 'radio') {
if ($(e).is(':checked')) {
formData.append($(e).attr('name'), $(e).val());
}
} else {
formData.append($(e).attr('name'), $(e).val());
}
});
// [type="file"] will be handled separately
$form.find('input[name][type="file"]').each(function(i, e) {
if ($(e)[0].files.length > 0) {
formData.append($(e).attr('name'), $(e)[0].files[0]);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.