jQuery.get 将请求排队,直到网络连接可用
我正在使用 jQuery Mobile 创建一个 Web 应用程序来查看和更新 CRM 类型系统。
移动应用程序使用 jQuery.get
和 jQuery.post
发送更新,并且当网络连接可用时它们可以正常工作。
当网络连接不可用时,我应该如何编码或使用什么来对 jQuery.get 和 jQuery.post 调用进行排队,以便在网络连接再次可用时发送它们。
I am using jQuery Mobile to create a webapp to look at and update a CRM type system.
The mobile app sends update using jQuery.get
and jQuery.post
and they work fine when network connection is available.
How should I code or what can I use to queue the jQuery.get
and jQuery.post
calls when the network connection is not available so they are sent when it becomes available again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:啊噗,我刚刚注意到你说“jQuery Mobile”,我最初将其读为 jquery for mobile 哈哈。嗯,这可能只有在 jQM 像普通 jquery 一样支持 ajax 的情况下才有效。
我有一个关于辅助 ajax 请求的想法,但你不应该需要它。只需像这样设置你的 AJAX,并给它一个超时时间。如果需要> 4(对于宽带连接来说应该足够了,但有些手机可能需要〜10-15)秒服务器才能响应,它只会再次尝试ajax请求,直到retryLimit,可以设置,然后也可以更改50 次结束后(即应该在程序空闲且没有数据时发送?)。连接后,它将进入 success 函数,然后该函数将数据发送到服务器。
所以它会是这样的:
Edit: ah poo, i just noticed you said 'jQuery Mobile', I initially read that as jquery for mobile lol. Ummm, this'll probably only work as long as jQM supports ajax the same as normal jquery
I had an idea with a secondary ajax request, but you shouldn't need that. Just set up your AJAX like this, and give it a timeout. If it takes > 4 (should be enough for a broadband connection, but some phones may need ~10-15) seconds for the server to respond, it'll just try the ajax request again up to retryLimit, which can be set, then changed later as well after the 50 times is up (i.e. should it send when the program is idle and has no data perhaps?). When it connects, it'll go to the success function, which will then send the data to the server.
So it'd be like: