JQuery超时问题
我发现使用 JQuery 超时存在问题,我有一个带有脚本的页面,它设置了超时并等待服务器的响应。 问题是当超时必须执行时,简而言之,它“不执行任何操作”。 我认为该脚本不会中断与服务器的连接并等待服务器响应,因为在服务器端,连接持续 10 秒(但超时设置为 5 秒)。 当服务器在与客户端不同的域名中工作时,我会看到此问题,而当服务器和客户端在本地工作时,则不会出现此问题。
您是否知道发生此错误的原因或如何关闭脚本连接?
// client
$.ajax({
type: "GET",
url: "some.php",
data: "name=John&location=Boston",
timeout: 5000,
success: function(msg){
alert( "Data Saved: " + msg );
},
error: function(request, errorType, errorThrown){
alert("opppsssss .... ");
}
});
和服务器代码:
//some.php
< ?
//simulate long task
sleep(10); //sleep 10 seconds
//send response
echo "some test data";
? >
最好的问候
多梅尼科
I have found a problem with use JQuery timeout, i have a page with script, it's set a timeout and waiting response from server. The problem is when timeout have to perform, in short words, it "no action". I think that script not interrupt the connection with server and wait for server response, because in server side the connection is on for 10 sec (but timeout is set 5 sec).
I see this problem when server work in different domain name then client, whereas when the server and client work in local this problem there isn't.
Have you a idea because this error happened or how to close the Script connection?
// client
$.ajax({
type: "GET",
url: "some.php",
data: "name=John&location=Boston",
timeout: 5000,
success: function(msg){
alert( "Data Saved: " + msg );
},
error: function(request, errorType, errorThrown){
alert("opppsssss .... ");
}
});
and the server code:
//some.php
< ?
//simulate long task
sleep(10); //sleep 10 seconds
//send response
echo "some test data";
? >
Best Regards
Domenico
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从表面上看,你是从后到前做的。 您已将超时设置为 5000 毫秒(5 秒),因此如果服务器端代码的响应时间超过 5 秒,它将超时。 你正在睡觉(10); 它休眠 10 秒,是指定超时时间的两倍。 解决此问题的方法是执行以下操作:
服务器代码:
希望有帮助。
You're doing it back-to-front by the looks of it. You've set the timeout to 5000 milliseconds (5 seconds) so if the server-side code takes longer to respond than 5 seconds it will timeout. You're doing sleep(10); which sleeps for 10 seconds, which is twice as long as the specified timeout. The way to fix this would be to do the following:
And the server code:
Hopefully that helps.