取消AJAX请求减缓后续导航 [英] Canceled AJAX request slows subsequent navigation

查看:93
本文介绍了取消AJAX请求减缓后续导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当用户请求报表jQuery的AJAX(使用 .load())调用了这点做了很多的一些运算和MySQL的请求文件的应用程序。一般需5-6秒加载和 .ajaxStart() .ajaxStop()被用来显示在装载过程中加载GIF。

On my application when user requests a report a jquery AJAX (using .load() ) call is made to a file that does a lot of number crunching and mySQL requests. it generally takes 5-6 seconds to load and .ajaxStart() and .ajaxStop() are employed to display a loading gif during the load.

这个问题:

如果用户点击生成报告按钮,然后改变了主意,试图导航到另一个网页应用程序挂起,不浏览到新的页面,5-6秒。我可以从去除加载GIF的的告诉.ajaxStop()立即触发试图导航到新页面时,但现在看来,Ajax请求之前的整理浏览器加载的下一个页面。

If a user clicks the 'generate report' button and then changes their mind and attempts to navigate to another page the application hangs, and doesn't navigate to the new page for 5-6 seconds. I can tell from the removal of the loading gif that .ajaxStop() fires immediately when attempting to navigate to a new page, but it appears that the ajax request is finishing before the browser loads the next page.

这是正常的行为呢?任何建议如何修复/重组呢?

Is this normal behavior? Any suggestions on how fix/restructure this?

推荐答案

我相信.ajaxStop()只取消一个Ajax请求,如果beforeSend回调返回false。在这种情况下,呼叫尚未启动,并且服务器没有收到一个请求。一旦请求被发送到服务器,页面没有长有控制权的请求,直到它返回。该.ajaxStop()请求大火从页面导航离开时,因为上一个Ajax调用做,如果有成功完成,因此将终止执行。

I believe .ajaxStop() only cancels an ajax request if the beforeSend callback returns false. In this case, the call has not been initiated and the server has not received a request. Once the request has been sent to the server, the page no long has control over the request until it returns. The .ajaxStop() request fires when navigating away from the page because the last ajax call made, if any completed successfully and therefore terminates execution.

该ajaxStop事件也触发,如果最后一个出色的Ajax请求被beforeSend回调函数中返回false取消。

The ajaxStop event is also triggered if the last outstanding Ajax request is cancelled by returning false within the beforeSend callback function.

以上是从jQuery API网站的 .ajaxStop()命令的摘录。这样看来,一旦呼叫已经取得和请求已发送您的服务器完成,即使用户导航到不同的页面调用。如果这么大的呼叫,它可能会导致您所遇到的延迟。

Above is an excerpt from the jquery api website for the .ajaxStop() command. It would appear that once the call has been made and the request has been sent your server is completing the call even though the user is navigating to a different page. If its that big of a call, it may cause the delay you're experiencing.

希望这有助于。

这篇关于取消AJAX请求减缓后续导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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