阿贾克斯长轮询无法正常工作 [英] Ajax long polling not working correctly

查看:128
本文介绍了阿贾克斯长轮询无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个简单的陌生人使用长轮询MVC 2.它,如果我打开应用程序不同的浏览器工作在我的机器罚款聊天应用程序..我的意思是,如果我在装IE和Mozilla的应用,它工作正常

如果我在浏览器中的两个标签接过机应用(例如:IE),长轮询不是从两个标签射击。我的意思是,有一个开始按钮开始聊这火长轮询。我可以看到它调用的行动,同时调试。而我的问题是,当我点击从标签之一启动按钮,它触发一个Ajax请求(长轮询(此req等待在服务器上,直到另一个reqst来))。然后我点击在标签两种启动按钮,直到第一个请求从服务器(超时后)回到住处不火的Ajax请求。

为什么发生这种情况?我读到这样的浏览器会阻止多个AJAX request..Is,一个原因是什么? ..它正常工作,如果我使用不同的browsers.The问题,如果我在同一个浏览器花了两个选项卡只能排


解决方案

  

我读到这样的浏览器会阻止多个Ajax请求。


是的,如果你用会话,ASP.NET阻止相同的会话并发请求。从文档报价:


  

访问ASP.NET会话状态
  独家每个会话,这意味着
  如果两个不同的用户使
  并发请求,获得每
  单独的会话被授予
  兼任。但是,如果两个
  并发请求的提出
  同一会话(通过使用相同的
  的SessionID值),第一个请求
  获取到会话独占访问
  信息。第二个请求
  仅在第一次请求之后执行
  结束了。 (第二次会议能
  还可以获得如果独占锁访问
  上的信息被释放,因为
  第一请求超出锁
  超时)。如果的EnableSessionState
  在@ Page指令值设置
  为只读,对于请求
  只读会话信息不
  导致对独占锁
  会话数据。但是,只读
  会话数据可能还是请求
  必须等待一个锁由一个设置
  读写会话数据的请求
  清楚了。


另外,还要确保你有禁用缓存。例如,如果你使用jQuery使用缓存:假选项时轮询:

  $。阿贾克斯({
    网址:'/民意调查,
    缓存:假的,
    成功:函数(结果){
        // ...
    }
});

I am developing a simple strangers chat 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) {
        // ...
    }
});

这篇关于阿贾克斯长轮询无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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