jQuery SCRIPT7002:XMLHttpRequest:网络错误 0x2ef3,由于错误 00002ef3 无法完成操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14527387/
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
SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3, Could not complete the operation due to error 00002ef3
提问by Jimmyt1988
I keep receiving this error when I do some Ajax calls...
当我执行一些 Ajax 调用时,我不断收到此错误...
It may even be something to do with Geocoding but I really have no idea how to capture the error to display something useful to users... or even how to solve the problem as it seems to just be referencing some kind of pointer or something :S 0x2ef3
它甚至可能与地理编码有关,但我真的不知道如何捕获错误以显示对用户有用的东西......甚至如何解决问题,因为它似乎只是在引用某种指针或其他东西: 0x2ef3
SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3, Could not complete the operation due to error 00002ef3.
SCRIPT7002:XMLHttpRequest:网络错误 0x2ef3,由于错误 00002ef3,无法完成操作。
An image might be more helpful than the error message:
图像可能比错误消息更有帮助:
Any ideas at all?
有什么想法吗?
My code fires off 10 ajax calls in 1 second to be processed by geocoding server side.
我的代码在 1 秒内触发 10 个 ajax 调用,由地理编码服务器端处理。
The error comes up intermittently. Sometimes I get geocoded results and sometimes I get that error. I would say I get it 10% of the time. It completely stops the ajax call from firing my error handler in jQuery.
错误间歇性出现。有时我会得到地理编码的结果,有时我会得到那个错误。我会说我有 10% 的时间得到它。它完全阻止了 ajax 调用在 jQuery 中触发我的错误处理程序。
采纳答案by NickNo
This is the fix that worked for me. There is invalid mime or bad characterset being sent with your json data causing that errror. Add the charset like this to help it from getting confused:
这是对我有用的修复程序。与您的 json 数据一起发送的无效 mime 或错误字符集导致该错误。添加这样的字符集以帮助它免于混淆:
$.ajax({
url:url,
type:"POST",
data:data,
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(){
...
}
});
Reference:
参考:
Jquery - How to make $.post() use contentType=application/json?
Jquery - 如何让 $.post() 使用 contentType=application/json?
回答by Jozef Briss
We also encountered similar problems. However, setting the charset as noted in the previous comment did not help. Our application was making an AJAX request every 60 seconds and our webserver, nginx, was sending Keep-Alive timeout at 60 seconds.
我们也遇到了类似的问题。但是,按照上一条评论中的说明设置字符集并没有帮助。我们的应用程序每 60 秒发出一次 AJAX 请求,我们的网络服务器 nginx 在 60 秒时发送 Keep-Alive 超时。
We fixed the problem by setting the keep-alive timeout value to 75 seconds.
我们通过将保持活动超时值设置为 75 秒来解决该问题。
This is what we believe was happening:
这是我们认为正在发生的事情:
- IE makes an AJAX request every 60 seconds, setting Keep-Alive in the request.
- At the same time, nginx knows that the Keep-Alive timeout value is ignored by IE, so it starts the TCP connection close process (in the case of FF/Chrome this is started by the client)
- IE receives the close connection request for the previously sent request. Since this is not expected by IE, it throws an error and aborts.
- nginx still seems to be responding to the request even though the connection is closed.
- IE 每 60 秒发出一次 AJAX 请求,在请求中设置 Keep-Alive。
- 同时nginx知道Keep-Alive超时值被IE忽略了,所以启动了TCP连接关闭过程(在FF/Chrome的情况下是由客户端启动的)
- IE 收到之前发送的请求的关闭连接请求。由于这不是 IE 所期望的,它会引发错误并中止。
- 即使连接已关闭,nginx 似乎仍在响应请求。
A Wireshark TCP dump would provide more clarity, our problem is fixed and we do not wish to spend more time on it.
Wireshark TCP 转储将提供更清晰的信息,我们的问题已解决,我们不希望在此上花费更多时间。
回答by Mike R
I received the same error (SCRIPT7002: XMLHttpRequest: Network Error 0x80004004, Operation aborted
), in our case it was because of JavaScript's same origin policy.
我收到了同样的错误 ( SCRIPT7002: XMLHttpRequest: Network Error 0x80004004, Operation aborted
),在我们的例子中是因为 JavaScript 的同源策略。
Our web app was making a JQuery AJAX call to our server on Port 8080. The call was getting intercepted and re-routed over SSL (due to server rules mandating that incoming traffic use SSL).
我们的 Web 应用程序在端口 8080 上对我们的服务器进行了 JQuery AJAX 调用。该调用被拦截并通过 SSL 重新路由(由于服务器规则要求传入流量使用 SSL)。
Once we made our web app load through the SSL port the issue was fixed.
一旦我们通过 SSL 端口加载我们的 Web 应用程序,问题就解决了。
回答by TRIDIB BOSE
This issue happened in my project because of an ajax GET call with a long xml string as a parameter value. Solved by the following approach: Making it as ajax post call to Java Spring MVC controller class method like this.
这个问题发生在我的项目中,因为 ajax GET 调用使用长 xml 字符串作为参数值。通过以下方法解决:将其作为对 Java Spring MVC 控制器类方法的 ajax post 调用,如下所示。
$.ajax({
url: "controller_Method_Name.html?variable_name="+variable_value,
type: "POST",
data:{
"xmlMetaData": xmlMetaData // This variable contains a long xml string
},
success: function(response)
{
console.log(response);
}
});
Inside Spring MVC Controller class method:
在 Spring MVC Controller 类方法中:
@RequestMapping(value="/controller_Method_Name")
public void controller_Method_Name(@RequestParam("xmlMetaData") String metaDataXML, HttpServletRequest request)
{
System.out.println(metaDataXML);
}
回答by Andrew Keeling
I had this problem, a an AJAX Post request that returned some JSON would fail, eventually returning abort, with the:
我遇到了这个问题,返回一些 JSON 的 AJAX Post 请求将失败,最终返回 abort,并显示:
SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3
SCRIPT7002:XMLHttpRequest:网络错误 0x2ef3
error in the console. On other browsers (Chrome, Firefox, Safari) the exact same AJAX request was fine.
控制台中的错误。在其他浏览器(Chrome、Firefox、Safari)上,完全相同的 AJAX 请求没问题。
Tracked my issue down - investigation revealed that the response was missing the status code. In this case it should have been 500 internal error. This was being generated as part of a C# web application using service stack that requires an error code to be explicitly set.
跟踪我的问题 - 调查显示响应缺少状态代码。在这种情况下,它应该是 500 内部错误。这是作为 C# web 应用程序的一部分使用服务堆栈生成的,需要显式设置错误代码。
IE seemed to leave the connection open to the server, eventually it timed out and it 'aborted' the request; despite receiving the content and other headers.
IE 似乎将连接打开到服务器,最终它超时并“中止”了请求;尽管收到了内容和其他标题。
Perhaps there is an issue with how IE is handling the headers in posts.
也许 IE 处理帖子中的标题存在问题。
Updating the web application to correctly return the status code fixed the issue.
更新 Web 应用程序以正确返回状态代码修复了该问题。
Hope this helps someone!
希望这可以帮助某人!
回答by Alexei
I have stumbled across this questions and answers after receiving the aforementioned error in IE11
when trying to upload files using XMLHttpRequest
:
IE11
在尝试使用XMLHttpRequest
以下方法上传文件时收到上述错误后,我偶然发现了这些问题和答案:
var reqObj = new XMLHttpRequest();
//event Handler
reqObj.upload.addEventListener("progress", uploadProgress, false);
reqObj.addEventListener("load", uploadComplete, false);
reqObj.addEventListener("error", uploadFailed, false);
reqObj.addEventListener("abort", uploadCanceled, false);
//open the object and set method of call (post), url to call, isAsynchronous(true)
reqObj.open("POST", $rootUrlService.rootUrl + "Controller/UploadFiles", true);
//set Content-Type at request header.for file upload it's value must be multipart/form-data
reqObj.setRequestHeader("Content-Type", "multipart/form-data");
//Set header properties : file name and project milestone id
reqObj.setRequestHeader('X-File-Name', name);
// send the file
// this is the line where the error occurs
reqObj.send(fileToUpload);
Removing the line reqObj.setRequestHeader("Content-Type", "multipart/form-data");
fixed the problem.
删除线reqObj.setRequestHeader("Content-Type", "multipart/form-data");
解决了问题。
Note:this error is shown very differently in other browsers. I.e. Chrome shows something similar to a connection reset which is similar to what Fiddler reports (an empty response due to sudden connection close).
注意:此错误在其他浏览器中的显示方式非常不同。即 Chrome 显示类似于连接重置的内容,这类似于 Fiddler 报告的内容(由于连接突然关闭而导致空响应)。
Also, this error appeared only when upload was done from a machine different from WebServer
(no problems on localhost).
此外,此错误仅在从不同于WebServer
(本地主机上没有问题)的机器上完成上传时出现。
回答by tekiegirl
I just want to add what solved this problem for me, as it is different to all of the above answers.
我只想添加为我解决这个问题的方法,因为它与上述所有答案都不同。
The ajax calls that were causing the problem were trying to pass an empty data object. It seems IE does not like this, but other browsers don't mind.
导致问题的 ajax 调用试图传递一个空数据对象。IE似乎不喜欢这个,但其他浏览器不介意。
To fix it I simply removed data: {},
from the ajax call.
为了修复它,我只是data: {},
从 ajax 调用中删除了。
回答by Roy
I had this error for some time and found a fix. This fix is for Asp.net application, Strange it failed only in IE non compatibility mode, but works in Firefox and Crome. Giving access to the webservice service folder for all/specific users solved the issue.
我有一段时间出现此错误并找到了解决方法。此修复程序适用于 Asp.net 应用程序,奇怪的是它仅在 IE 非兼容模式下失败,但在 Firefox 和 Crome 中有效。为所有/特定用户授予对 webservice 服务文件夹的访问权限解决了该问题。
Add the following code in web.config file:
在 web.config 文件中添加以下代码:
<location path="YourWebserviceFolder">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
回答by Ankit Tomar
With the Apache 2 change KeepAliveTimeout
set it to 60 or above
使用 Apache 2 更改KeepAliveTimeout
将其设置为 60 或更高
回答by Derrick.X
Have encountered the same issue in my asp.net project, in the end i found the issue is with the target function not static, the issue fixed after I put the keyword static.
在我的asp.net项目中遇到了同样的问题,最后我发现问题是目标函数不是静态的,我把关键字static后问题解决了。
[WebMethod]
public static List<string> getRawData()