中止 Google 可视化查询
使用 Google Visualization API 中的查询对象,我需要找到一种方法来中止请求。我正常设置查询:
var qMyQuery=new google.visualization.Query('http://myurl');
qMyQuery.send(queryDoneCallbackFunctionName);
我尝试了 .abort
方法,但这仅适用于定期刷新数据。我也尝试过设置 qMyQuery=null
,但这没有任何作用。
当数据返回到回调时,我不能简单地丢弃数据......这样做的目的是在用户请求时停止服务器上非常冗长的查询。
有什么建议吗?谢谢。
Using the Query object in the Google Visualization API, I need to find a way to abort a request. I set up the query normally:
var qMyQuery=new google.visualization.Query('http://myurl');
qMyQuery.send(queryDoneCallbackFunctionName);
I have tried the .abort
method, but that only applies to regularly refreshing data. I have also tried setting qMyQuery=null
, but that didn't do anything.
I cannot simply discard the data when it is returned to the callback... the point of this is to stop a very lengthy query on the server, if requested by the user.
Any suggestions? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的解决方案似乎是使用自定义 XHR 对象、jQuery、ExtJS 等手动向 google 发送请求。然后您将拥有完全的权力通过按钮单击处理程序或任何您想要的方式取消用户发出的命令请求。
Google的可视化查询模块确实允许它在图表DIV中自动向用户显示错误,但除此之外,你不能只使用自己的XHR对象吗?
构建自定义 XHR 对象、使用 jQuery、ExtJS Ajax 或类似的东西。
The simplest solution would seem to be to send the request to google manually using a custom XHR object, jQuery, ExtJS, etc. Then you would have full power to cancel the request on command from a user through button click handlers or whatever you would like.
Google's visualization query module does allow it to display errors automatically to the user in the chart DIV, but otherwise, can't you just use your own XHR object?
Either build a custom XHR object, use jQuery, ExtJS Ajax, or something of the sort.
如果您只是想在客户端取消 Ajax 请求,您应该查看这个问题 使用 jQuery 中止 Ajax 请求
但是为了保存服务器资源,您必须发出新的 AJAX 请求,从而消耗客户端和服务器中的另一组资源。
此类中止请求的服务器端实现将需要验证将存储在共享位置(例如数据库)中的标志。
您必须仔细计算或测量才能看到此类实施的成本效益
If you simply want to cancel the Ajax request in the client side you should look this question Abort Ajax requests using jQuery
But to save the Server resources you have to emit a new AJAX request, consuming another set of resources both in the client and in the server.
The server side implementation of such abort request would require the verification of a flag which would be stored in a shared location, such as a database.
You have to calculate or measure carefully to see the cost-benefit of such implementation