简体   繁体   中英

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.

On the opposite side; removing the google.setOnLoadCallback works in Chrome but not Firefox: http://jsfiddle.net/RTQ5S/

Any ideas on a compromise?

I am guessing Chrome doesn't run the setOnLoadCallback because it has already loaded.

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. 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. So based on your fiddle, I would replace window.addEvent('domready', function(){..}); with 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.

See 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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