douke7274
2012-01-10 06:21
浏览 112

jquery ajax多个请求

I've made a long-polling like a request in a function using jQuery ajax, which will run all the time. There is another request made to send data to PHP back-end file and this second request is not long-polling, it just sends data to that PHP file.

Problem: I examined with Firebug that when the long-polling request is running, I'm not able to send another request as long as the long-polling is running. How do I send another request even if the long-polling is running?

Note: I've used async: true in both.

another question: how do I make sure that even the function which holds long-polling request code will be called multiple times, but the long-polling request will be made only and only one?

图片转代码服务由CSDN问答提供 功能建议

我在一个使用jQuery ajax的函数中做了一个像轮询一样的长轮询,它会一直运行 。 还有另一个请求将数据发送到PHP后端文件,第二个请求不是长轮询,它只是将数据发送到该PHP文件。

问题:我使用Firebug进行了检查 当长轮询请求运行时,只要长轮询正在运行,我就无法发送另一个请求。 即使长轮询正在运行,如何发送另一个请求?

注意:我在两者中都使用了 async:true \ n

另一个问题:如何确保即使是持有长轮询请求代码的函数也会多次调用,但长轮询请求只会进行一次? \ n

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douan6815 2012-01-10 07:17
    已采纳

    Does your php use session based authentication? Your problem might be session locking. This can occur in PHP that uses session_start() unconditionally at the top of each request, and is sometimes default behavior in an MVC framework even if the session is never modified. Other suspect use cases is if both scripts depend on being logged in as an admin user.

    If you suspect this might be the case, try strategic placement of session_write_close() at the earliest possible point after you no longer need to modify session data for your two scripts.

    点赞 评论
  • dongxiangshen7916 2012-01-10 06:28

    You need to use async : true (which is the default).

    If you say async : false that means it does a synchronous request, i.e., it waits for the first request to finish before doing anything else. You want an asynchronous request so that the browser can keep doing other things while waiting for the response from the first request.

    (There is rarely a need for async : false, and if you're not sure whether you need it you almost certainly don't.)

    点赞 评论
  • dongnai5905 2018-08-30 23:18

    Multiple requests with Ajax, Jquery.

    By default Jquery already makes asynchronous requests; however, the 'queuing' problem does not happen in Javascript code unless you are using the async: false option; which would obviously block the browser until the request was terminated. In addition, this problem can occur for the following reasons:

    1 - Using PHP's built-in server - Using this feature of PHP 5.5, responses to requests are made one after another on the same machine, that is, on the same computer. However, I recommend that you test the scripts using the latest version of the XAMP server;

    2 - Use of sessions - For each session the responses to requests are presented in queues, not in parallel, however, it is recommended to use session_write_close;

    3 - Unintended configuration of the MaxClients option of the directive in Apache - In case the first and / or second option does not occur; the third for sure, is the problem. To resolve, simply access the httpd-npm file and configure the MaxClients (256) option for multiple requests. In the current version of Apche, if I'm not mistaken, the MaxClients option has been replaced by MaxConnectionsPerChild.

    Therefore, the options presented also depend on the contexts also presented. Hope this helps.

    点赞 评论

相关推荐 更多相似问题