[英]Ajax request with formdata returns error 'request entity too large'
我正在嘗試使用FormData發送帶有文件的表單,並且在現代台式機瀏覽器中可以正常工作,但是在移動設備中,我的代碼返回錯誤“請求實體太大”。 我已經在iPhone 5s(iOS 11)Safari和Android Firefox上進行了測試。
有代碼:
window.xhrJson = function (url, method, data, customParams) {
return xhr(url, method, 'JSON', data, customParams);
};
window.xhr = function (url, method, dataType, data, customParams) {
var params = {
url: url,
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
method: method,
dataType: dataType
};
if (typeof data !== 'undefined') {
params.data = data;
}
if (typeof customParams !== 'undefined') {
params = mergeOptions(params, customParams);
}
return $.ajax(params);
};
window.mergeOptions = function(obj1,obj2){
var obj3 = {};
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
return obj3;
};
// Main function to upload form with files
window.upload = function ($form, url) {
var xhr = xhrJson(url, 'POST', new FormData($form[0]), {
contentType: false,
processData: false
});
xhr.fail(function (data, status, err) {
alert(err);
}).done(function (data) {
});
return xhr;
};
好的,我發現了問題。 我的手機使用了未正確配置的本地代理服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.