简体   繁体   English

Google Chrome和可视化google.setOnLoadCallback在Ajax中失败

[英]Google Chrome & Visualization google.setOnLoadCallback fails in ajax

See http://jsfiddle.net/QJVUr/1/ for an example - works fine in FF but not in Chrome. 有关示例,请参见http://jsfiddle.net/QJVUr/1/-在FF中可以正常工作,但在Chrome中不能正常工作。

On the opposite side; 在另一边 removing the google.setOnLoadCallback works in Chrome but not Firefox: http://jsfiddle.net/RTQ5S/ 删除google.setOnLoadCallback可以在Chrome中使用,但不能在Firefox中使用: http : //jsfiddle.net/RTQ5S/

Any ideas on a compromise? 有什么折衷办法吗?

I am guessing Chrome doesn't run the setOnLoadCallback because it has already loaded. 我猜Chrome不会运行setOnLoadCallback,因为它已经加载了。

I would suggest two things: 我建议两件事:

  • Ideally your AJAX call would only fetch data, and would pass this data to a callback function which would build the gviz DataTable and draw your charts. 理想情况下,您的AJAX调用只能获取数据,并将该数据传递给回调函数,该函数将构建gviz DataTable并绘制图表。 See an example of how that would go down here . 请参阅此处的示例。
  • The purpose of google.setOnLoadCallback is ( according to these docs ) to wait until the google libraries and the html page are loaded so that things can start to happen. google.setOnLoadCallback的目的是( 根据这些文档 )是要等到google库和html页面加载完毕后,事情才能开始发生。 So based on your fiddle, I would replace window.addEvent('domready', function(){..}); 因此,根据您的摆弄,我将替换window.addEvent('domready', function(){..}); with google.setOnLoadCallback(function(){...}); 使用google.setOnLoadCallback(function(){...}); .

Hopefully that helps; 希望能有所帮助; I'm not sure if there's a reason they way you're doing things the way you are that means the above options aren't what you're looking for, so if that's the case feel free to give more specifics in your question. 我不确定他们是否有理由按照自己的方式行事,这意味着上述选项不是您想要的,因此,在这种情况下,您可以随意提出更多问题。

Instead of using setOnCallback set the callback in the library load. 代替使用setOnCallback设置库加载中的回调。

See http://jsfiddle.net/QJVUr/10/ http://jsfiddle.net/QJVUr/10/

google.load('visualization', 1, {packages:['corechart'], callback: drawChart});

Per Google dev docs, if library is already loaded, it is not loaded again, rather the callback is immediately called. 根据Google开发文档,如果已经加载了库,则不会再次加载该库,而是会立即调用该回调。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM