带有ajax的Java-ERR_EMPTY_RESPONSE-服务器处理请求时Ajax响应引发错误 [英] Java with ajax - ERR_EMPTY_RESPONSE - Ajax response throws error while server is processing the request

查看:569
本文介绍了带有ajax的Java-ERR_EMPTY_RESPONSE-服务器处理请求时Ajax响应引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在浏览器控制台中遇到错误.

I am getting below error in the console of browsers.

无法加载资源:net :: ERR_EMPTY_RESPONSE

Failed to load resource: net::ERR_EMPTY_RESPONSE

我的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:

/xxxx/reports/2016-06-15/07-03-53-237-r1Qn/xxx-smoketest-report.html

/xxxx/reports/2016-06-15/07-03-53-237-r1Qn/xxx-smoketest-report.html

我在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上运行的声音,但我不太熟悉,但是您可以在

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):

我还要赞同@ DelightedD0D关于使用服务工作者或其他某种机制(例如轮询)的建议. AJAX并不是真正为请求而构建的,因此您可能会遇到其他问题.

I would also second @DelightedD0D 's suggestion of using service workers or some other mechanism (such as polling). AJAX isn't really built for requests this long, so you'll likely run in to other issues.

即使我指向的文档也建议不要将其设置为极值.

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:

@TheMadDeveloper DelightedD0D:从你们的建议来看,我正在考虑将websocket用于这种情况.您认为这是个好主意吗?虽然我被卡在stackoverflow.com/questions/37940540/

@TheMadDeveloper DelightedD0D: From what you guys have suggested I am thinking to use websocket for this scenario. Do you think it's a good idea? although I am stuck stackoverflow.com/questions/37940540/

我认为这是一个明智的决定,尽管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响应引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆