Javascript 带有formdata的Ajax请求返回错误';请求实体太大';

Javascript 带有formdata的Ajax请求返回错误';请求实体太大';,javascript,ajax,html,file-upload,Javascript,Ajax,Html,File Upload,我尝试使用FormData发送带有文件的表单,在桌面现代浏览器中,它工作正常,但在手机中,我的代码返回错误“请求实体太大”。 我已经在iPhone5S(iOS11)Safari和android Firefox上进行了测试 代码如下: window.xhrJson = function (url, method, data, customParams) { return xhr(url, method, 'JSON', data, customParams); }; window.xhr

我尝试使用FormData发送带有文件的表单,在桌面现代浏览器中,它工作正常,但在手机中,我的代码返回错误“请求实体太大”。 我已经在iPhone5S(iOS11)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;
};

好的,我发现了问题。我的手机使用了未正确配置的本地代理服务器。

与服务器设置有关,与Ajax无关。您发送的文件大小大于服务器允许的大小。我已更改服务器上所有可能的设置。正如我在桌面上所说,它工作正常,我发送了70Mb大小的图像。