问题描述
我目前正在实施一种HTTP推送的使用长轮询不支持多部分Ajax响应浏览器。
I am currently implementing a sort of HTTP Push using Long Polling for browsers that don't support multipart ajax responses.
我不得不承认,在服务器端工作正常,我是relativly新的前端JavaScript开发,因此可能已经取得了一些明显的错误
I have to admit that while the server side is working fine, i am relativly new to front end javascript development, and thus may have made some obvious mistakes
现在的问题是如下LongPolling完美的作品在IE 6,7,8和Firefox(尽管Firefox使用多部分我与长轮询测试它太),但Safari和Chrome进入在Ajax请求的浏览器的忙的状态。 (它们显示窗口等待光标,和Safari也显示在标题栏中的加载指示器)
The problem is as follows LongPolling works perfectly on IE 6,7,8 and Firefox ( even though Firefox uses multipart i tested it with long polling too ) but Safari and Chrome enterthe browsers "busy" state during the ajax requests. ( they show the windows wait cursor, and Safari also shows its "Loading" indicator in the title bar )
这当然不是desireable ..
This is of course not desireable..
下面是我的code做基于jQuery 1.4.1长轮询:
Here is my code to do the long poll based on Jquery 1.4.1:
function MepSubscribeToQueueLongPoll(name, callback) {
var queueUrl = MepGetQueueUrl(name, "LongPoll");
MepLongPollStep(queueUrl, callback);
};
function MepLongPollStep(url, callback) {
$.ajax({
url: url,
async: true,
cache: false,
success: function (data,status,request) {
callback(request.responseText);
MepLongPollStep(url, callback);
}
});
};
请注意,我绕过通过直接传递request.responseText回调解析的jQuery功能的数据因为jQuery似乎不支持多部分AJAX阶跃响应,我想成为整个通信路径是一致的。
Note that i am bypassing the data parsing functionality of Jquery by passing the request.responseText directly to the callback because Jquery does not seem to support multipart ajax respones and i wanted to be consistent across communication paths.
推荐答案
由于没有更好的答案已经走上前去,我不知道一个简单的超时可以解决这个问题。对不起,给一个猜测,而不是我知道这是真正的答案,但这实际上可能解决它:
Since no better answer has stepped forward, I wonder if a simple timeout would solve the problem. Sorry to give a "guess" instead of a "I know this to be true answer", but this might actually fix it.:
function MepLongPollStep(url, callback) {
$.ajax({
url: url,
async: true,
cache: false,
success: function (data,status,request) {
callback(request.responseText);
window.setTimeout( function(){
MepLongPollStep(url, callback);
},10);
}
});
};
这篇关于Browers进入"忙QUOT;国家对Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!