简体   繁体   English

jQuery.ajax()错误,textStatus =错误

[英]jQuery.ajax() error with textStatus=error

The jQuery.ajax() function I use works correctly most of the time. 我使用的jQuery.ajax()函数大多数时候都能正常工作。 However sometimes it is not returning any data. 但有时它不会返回任何数据。 Instead the error() function is called. 而是调用error()函数。

$.ajax({

  [...]

  , error: function(jqXHR, textStatus, errorThrown) {
    console.log(jqXHR);
    console.log(textStatus);
    console.log(errorThrown);
  }
});

I can see in there that in those cases textStatus is 'error' and errorThrown is '' (empty). 我可以在那里看到,在那些情况下textStatus'error'errorThrown'' (空)。

The jQuery documentation just lists the possible values of textStatus ( "timeout" , "error" , "abort" , and "parsererror" ). jQuery文档只列出了textStatus的可能值( "timeout""error""abort""parsererror" )。 However it does not describe, what 'error' means. 但它没有描述, 'error'意味着什么。

jqXHR returns an object but it does not seam to reveal any additional insights. jqXHR返回一个对象但它没有接缝以显示任何其他见解。

How can I investigate what the source to this issue is? 我如何调查此问题的来源是什么?

Found out it happens, whenever Reload is pressed in the browser, while the ajax request was still running. 发现它发生,只要在浏览器中按下重新加载,而ajax请求仍在运行。

This post helped me implement a solution. 这篇文章帮我实现了一个解决方案。

I would suggest you to use fiddler to monitor the request and analyze what you are getting in response. 我建议你使用fiddler来监控请求并分析你得到的回应。

Another thing to try is to compose your ajax request in fiddler composer. 另一件要尝试的是在fiddler composer中编写你的ajax请求。 This way you can figure out whether your are passing all required headers or not. 这样你就可以弄清楚你是否正在传递所有必需的标题。

You will find more details in fiddler. 你会在fiddler找到更多细节。

As KidA said in the comment try this: 正如KidA在评论中所说,试试这个:

console.log(jqXHR.status);

Also, just make sure you are pulling from the right destination (url, listname, etc.) along with the proper data type pull (POST, GET, UPDATE, DELETE, etc.) 此外,只需确保从正确的目标(url,listname等)拉出正确的数据类型pull(POST,GET,UPDATE,DELETE等)

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

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