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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29944622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:22:26  来源:igfitidea点击:

jQuery.ajax() error with textStatus=error

javascriptjqueryajaxxmlhttprequest

提问by JochenJung

The jQuery.ajax()function I use works correctly most of the time. However sometimes it is not returning any data. Instead the error()function is called.

jQuery.ajax()我使用的函数大部分时间都可以正常工作。但是有时它不返回任何数据。而是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 textStatusis 'error'and errorThrownis ''(empty).

我可以在那里看到,在这些情况下,textStatus'error'errorThrown''(空)。

The jQuery documentationjust lists the possible values of textStatus("timeout", "error", "abort", and "parsererror"). However it does not describe, what 'error'means.

jQuery的文档只是列出了可能的值textStatus"timeout""error""abort""parsererror")。然而它没有描述,是什么'error'意思。

jqXHRreturns an object but it does not seam to reveal any additional insights.

jqXHR返回一个对象,但它不会显示任何其他见解。

How can I investigate what the source to this issue is?

如何调查此问题的根源?

采纳答案by JochenJung

Found out it happens, whenever Reload is pressed in the browser, while the ajax request was still running.

发现它会发生,每当在浏览器中按下 Reload 时,而 ajax 请求仍在运行。

This posthelped me implement a solution.

这篇文章帮助我实施了一个解决方案。

回答by Giridhar Prakash Yellapu

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. This way you can figure out whether your are passing all required headers or not.

另一件要尝试的事情是在 fiddler composer 中编写您的 ajax 请求。通过这种方式,您可以确定您是否正在传递所有必需的标头。

You will find more details in fiddler.

您将在 fiddler 中找到更多详细信息。

回答by BesaseB

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、列表名等)以及正确的数据类型拉取(POST、GET、UPDATE、DELETE 等)