2

This was something that I struggled with, and found the answer on stackoverflow, so I thought I should share it.

This is Jquery syntax.

$.ajax({
   url:  'AjaxPHPScript.php'
   type: 'POST',
   data: "chartdata="+chartdata, // this is what I pass to the Ajax call 
   success: function(result) {   
     // this is when it comes back from Ajax 
     // this will NOT work
     $("#"+contentdiv).highcharts(result);           

     // this will
     // the parentheses around the JSON results inside the eval function is the key!
     var chartstuff=eval("("+result+")");      
     $("#"+contentdiv).highcharts(chartstuff);           

     // I did not discover this on my own, I got the lead from this post:
     // http://stackoverflow.com/questions/13718326/javascript-string-to-object     
   },
    error: function(e) {             
     console.log(e); 
     console.log(JSON.stringify(e));
   } 
 });            
candlejack
  • 1,189
  • 2
  • 22
  • 51
  • While this could be valuable, to make it fit into StackOverflow you should first post it as a question (what is the problem), and then answer it yourself, with the code that you figured out to solve the problem. This post is not a question. – Halvor Holsten Strand Mar 28 '15 at 14:47

0 Answers0