Javascript Highcharts Ajax

Javascript Highcharts Ajax,javascript,jquery,ajax,highcharts,object-literal,Javascript,Jquery,Ajax,Highcharts,Object Literal,这是我努力解决的问题,在stackoverflow上找到了答案,所以我想我应该分享一下 这是Jquery语法 $.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 ba

这是我努力解决的问题,在stackoverflow上找到了答案,所以我想我应该分享一下

这是Jquery语法

$.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));
   } 
 });            

虽然这可能很有价值,但要使其适合StackOverflow,您应该首先将其作为问题发布(问题是什么),然后自己回答,并使用您找到的解决问题的代码。这篇文章不是问题。