Ajax long polling not working correctly
I am developing a simple strangers c开发者_如何学JAVAhat application using long polling in MVC 2. Its works fine in my development machine if i am opening the application different browsers.. i mean if i loaded the application in IE and mozilla, it works fine
if i took the appliction in two tabs of a browser (eg:IE) , the long polling are not firing from both tabs.. I mean, there is a start button to start chat which fire long polling. I can see it calling actions while debugging.. And my problem is, When i clicked start button from tab one , it fire a ajax request (long polling ( this req wait at server till another reqst comes)).and then i click the start button in tab two, it does not fire the ajax request until the first request is returned from the server(after timeout).
why this is happening? I read like browser will block multiple ajax request..Is that a reason for that? ..It work fine if i am using different browsers.The problem only came if i took two tab in same browser
I read like browser will block multiple ajax request.
Yes, if you use sessions, ASP.NET blocks concurrent requests from the same session. Quote from the documentation:
Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished. (The second session can also get access if the exclusive lock on the information is freed because the first request exceeds the lock time-out.) If the EnableSessionState value in the @ Page directive is set to ReadOnly, a request for the read-only session information does not result in an exclusive lock on the session data. However, read-only requests for session data might still have to wait for a lock set by a read-write request for session data to clear.
Also make sure that you have disabled caching. For example if you use jquery use the cache: false
option when polling:
$.ajax({
url: '/poll',
cache: false,
success: function(result) {
// ...
}
});
精彩评论