简体   繁体   English

由于 JSON 响应较大,AJAX 请求失败

[英]AJAX request is failing because of large JSON response

I having a problem with the following function:我在使用以下功能时遇到问题:

function get_request(url){
    $.ajax({
        type: 'GET',
        url: url
        success: function(response){
            get_request_success(response)
        },
        fail: function(){
            get_request_fail()
        }
    });

the server is giving a normal 200 response with the response in the body.服务器在正文中给出了正常的 200 响应。

this is the response header (irrelevant data is deleted) Content-Type: application/json content-Lenght: 47954 Server: Werkzeug/1.0.0 Python/3.76这是响应头(删除无关数据) Content-Type: application/json content-Lenght: 47954 Server: Werkzeug/1.0.0 Python/3.76

if I inspect the browser and I go to network, the data is in the response body.如果我检查浏览器并访问网络,则数据在响应正文中。 so I think that the Jquery code is too quickly concluding that the request is failing, but I am not sure所以我认为 Jquery 代码很快就得出请求失败的结论,但我不确定

errorcode:错误代码:

{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
ParseError
No conversion from text to application/json

problem was a server side problem.问题是服务器端问题。 Because the server was a python application that was ussing pandas it was passing NaN (not a number) values into the JSON respond.因为服务器是一个使用 Pandas 的 Python 应用程序,所以它会将 NaN(不是数字)值传递到 JSON 响应中。 JS did not understand this ofcourse. JS当然不明白这一点。 solution was found to run a .fillna("") on the dataframe.发现解决方案在数据帧上运行 .fillna("") 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM