javascript - Google setOnLoadCallback and Ajax -


i using ajax hit url serves json through node.js/express. json returned fine, , have tested it. data receives should plotted in graph using google chart api (which works fine if array hard-coded).

i recieving 4 unexpected 'uncaught typeerrors' , appreciate being pointed in right direction.

your assistance appreciated, , welcomed!

enter image description here

here code in question (i think)

 <!-- <script>             var ndata;         $(document).ready(function() {             $.ajax({                 url: 'http://localhost:3000/renderedjson',                 type: 'get',                 datatype: 'json',                 data: [],                 success:function(data){                 ndata = data;                 console.log("success");                 console.log(ndata);                 }             })             .done(function() {                 console.log("done");                 getdata();             })             .fail(function() {                 console.log("error");             })             .always(function() {                 console.log("complete");             });             });         </script> 

here example (with hard coded data, working! see, comment ajax request , uncomment hardcoded variable)

update - here payload, working url setup through express / node (which makes call mongodb instance)

[{"_id":"559c27abe01e815c0f7b69d3","date":"2015-01-2","one":[{"a":9},{"b":8},{"c":7},{"d":6},{"e":5},{"f":4},{"g":3}],"two":[{"h":2},{"i":1}]},{"_id":"559c27abe01e815c0f7b69d2","date":"2015-01-1","one":[{"a":1},{"b":2},{"c":3},{"d":4},{"e":5},{"f":6},{"g":7}],"two":[{"h":8},{"i":9}]}] 

update after further debugging, believe following code not firing off.

 google.setonloadcallback(function() { console.log('loaded google 1'); drawchart(cols, rows); console.log('loaded google 2'); }); 

the data undefined getdata() function. code have posted incomplete. looking @ fiddle there line between getdata , drawchart functions: getdata();
calls getdata function before ajax call has been completed. remove line , should work.

  • its hard see errors on picture.
  • the errors on picture relate places errors happening showing ajax isnt enough debug problem (just furture reference)
  • its idea if things undefined check them within function thats throwing errors. in case if log ndata within getdata output undefined - can lead problem has originated.

edit

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>     google.load('visualization', '1.1', {packages: ['line']}); 

then instead of

google.load('visualization', '1.1', {packages: ['line']}); google.setonloadcallback(function() {     drawchart(cols, rows); }); 

jus have:

drawchart(cols, rows); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -