问题描述
我在浏览器控制台中遇到错误.
I am getting below error in the console of browsers.
我的ajax调用适用于所有按钮单击,但是此错误仅适用于一个按钮(比如说 testExt 按钮).单击这些按钮时,后台脚本运行并执行一些测试.唯一的区别是,此 testExt 需要更多的时间来完成其执行(将近4分27秒),但是响应会在4分16秒时在ajax的error
块中到达客户端,即使脚本已在服务器端成功执行.
My ajax call works for all the button clicks, but this error is coming only for one button (lets say testExt button).On clicking on these buttons, a background script runs and execute some tests. The only difference is that this testExt takes more time to complete its execution (nearly 4 min 27 secs) but the response comes to client at 4 min 16 secs in the error
block of ajax even when the script is successfully executed at server's end.
控制台显示以下错误:
Object {readyState: 0, responseText: "", status: 0, statusText: "error"}
Ajax代码:
$.ajax({
type : "Get",
url : "resultValue.htm",
cache: false,
data : "testName=" + name,
success : function(response) {
// success logic here
},
error: function(jqXHR, textStatus){
console.log(jqXHR);
alert('There has been server side error. Please contact TechEng team to get this fixed.')
}
});
从此请求返回的响应只是一个行字符串:
The response which is returned from such request is just one line string:
我在SO上搜索了一些问题,但是由于我也尝试增加内存大小,因此我不确定服务器端是否存在Java内存问题.请帮助我了解发生了什么问题.我是否缺少某些情况来处理此ajax
请求
I googled some questions on SO but I am not sure if its a java memory issue on server side as I tried to increase memory size as well. Please help me to understand what's going wrong. Am I missing certain scenario to handle this ajax
request
当我直接点击服务器API时,我在浏览器上收到以下响应:
When I directly hit the server API, i get following response on browser:
FireFox:
Chrome
推荐答案
这听起来确实像您遇到了某种超时.在任何地方都可以超时4分钟以上的请求-浏览器,Web服务器,应用程序服务器...甚至网络设备和操作系统.通常,最低的超时值是由Web服务器设置的.
It does sound like you are running up against some kind of a timeout. There are any number of places where a 4+ minute request can be timed out--browser, web servers, application servers...maybe even network devices and operating systems. Usually, the lowest timeout values are set by web servers.
听起来像您在tomcat上运行的声音,但我不太熟悉,但是您可以在 https://tomcat.apache.org/connectors-doc/common_howto/timeouts.html .可能有一种方法可以配置asyncTimeout
之类的东西.
Sounds like your running on tomcat, which I'm less familiar with, but you might be able to find some good information at https://tomcat.apache.org/connectors-doc/common_howto/timeouts.html. There's likely a way to configure things like asyncTimeout
.
但是,我要重申我之前的评论(我知道你已经注意了):
However, I would reiterate my prior comment (which I know you've taken heed of):
即使我指向的文档也建议不要将其设置为极值.
Even the documentation I pointed to recommends against setting these to extreme values.
正如我所提到的,听起来您正走了一条与您的评论不同的路线:
As I mention, it sounds like you ARE going a different route, from your comment:
我认为这是一个明智的决定,尽管websocket可能有点过分.据我了解,在执行任务时,您实际上并不需要服务器和客户端保持不断的交谈.真的,您只想知道什么时候完成.
I think this is a wise decision, although websockets maybe be a little bit of an overkill. From what I gather, you don't really need the server and the client to be constantly talking while your task is being performed. Really, you just want to know when it's finished.
如果您在websocket的路径上走得太远,可以看看服务器发送的事件(SSE).
If you haven't gone too far down the websocket path, you might take a look at Server-Sent Events (SSE).
这篇文章具有一些特定于Tomcat的信息. 另请参阅此帖子以获取SSE和websocket的详细比较
This post has some info that's specific to Tomcat. Also see this post for a detailed comparison of SSE and websockets.
希望有帮助!
这篇关于带有ajax的Java-ERR_EMPTY_RESPONSE-服务器处理请求时Ajax响应引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!