Skip to content Skip to sidebar Skip to footer

Ajax Json Query Directly To Python Generated Html Gets Undefined

I've been struggling three weeks for now and I'm at the dead end. Sysadmins are s*tty developers :) I'm trying to build lightweight cgi-bin python scripts to collect data and conve

Solution 1:

If I'm reading your javascript correctly, the responseText property is only set after the request has completed. Normally, these things execute asynchronously, so you register a function to be called after the data has been received. e.g.

function drawTable() {
  var drawChart = function(jsonData) {
      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(jsonData);

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
      chart.draw(data, {width: 400, height: 240});
  };

  $.ajax({
      type: "GET",
      url: "http://192.168.1.123:8099/cgi-bin/test.py",
      dataType:"json",
      async: false
  }).done(drawChart);

}

More examples can be found on in the jquery ajax documentation.


Post a Comment for "Ajax Json Query Directly To Python Generated Html Gets Undefined"