开发者

simple php data to jquery (json)

I'd like to plot a simple graph using data from PHP and jqplot.

In PHP I simply did this:

$test = array('1' => '2', '3' => '4'); 
echo json_encode($test); 

The result that I get on js side is: {"1":"2","3":"4"}, I checked this.

So, I've tried to plot this simple array but no luck:

$.ajax({  
  开发者_运维百科    type: "POST",  
      url: "ajax.php",  
      data: "fname="+ fname +"& lname="+ lname,
      dataType:"json", 
      success: function(data)
        {  
        $('#dissapear').hide(function(){$('#chartdiv').css("height:400px;width:300px;");$('#chartdiv').fadeIn();});
        $.jqplot
         ('chartdiv', [data], 
           {
           title:'Jitter',
           axes:{yaxis:{min:0,max:240},xaxis:{renderer:$.jqplot.DateAxisRenderer}},
           series:[{lineWidth:4, markerOptions:{style:'square'}},{ show: true } ]
           }
         );

What did I miss? Please help me out, I've tried at least 20 code combinations but no luck. And yeah, I did look at dataRenderer examples in jqplot, but it didn't help me.


I'm not familiar with jqplot, but it seems to me that:

$test = array('1' => '2', '3' => '4'); 

should probably be

$test = array(1 => 2, 3 => 4);

That is, you don't need the array values to be strings.


I believe the problem comes in when you return the json... your javascript doesn't understand that it's an array. There is no "as array" typecasting so I'm scratching my head on this one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜