Skip to content Skip to sidebar Skip to footer

Trying To Load Google Charts Through A (jQuery)ajax Call

Possible Duplicate: Trying to load Google charts through a jQuery ajax call I've been at this all day and cannot think of a way to make this work. I am not very familiar with jQ

Solution 1:

make your button by default disabled

load Google API in your js file, on load callback enable your button

// Set a callback to run when the Google Visualization API is loaded.     
google.setOnLoadCallback(function(){  $("#post_yes").removeAttr('disabled'); });

move the drawChart function to your js file, add a parameter 'rows'

function drawChart(rows) {
  ...
  data.addRows(rows);
  ...
}

inside php file build needed rows and return them (as valid json)

on btn click post your data, on success callback call the drawChart function and pass returned rows to it

$.post(
  "query.php",  
  {answer: "yes", poll_id: 5},  
  function(response){ 
    drawChart(response);
  }
);


or if you don't want to disable the button you can on post success first load google API and on that loading callback call drawChart with passed response // function(){ drawChart(response); }

Post a Comment for "Trying To Load Google Charts Through A (jQuery)ajax Call"