Trying to implement JSON and AJAX

Share RGraph:   To help my Google visibility (it can't get much worse!), if you like and use RGraph I'd appreciate it if you could link to me

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Kyle on 10th October 2012
Hi there,

I am trying to implement AJAX into my charts and cannot for the life of me get it working.
Tried for the last 6 hours!!

I am encoding a PHP array with json_encode();

it is returning {"linechartvalues":"[2,0.33,0.22]"}

when I do the following it works...
var test2 = [2,0.33,0.22];

but if I parse the JSON, and do this...
var test = jsonstuff.linechartvalues;

it doesnt work.
if I alert(test) and (test2);
they both echo the EXACT SAME THINGS [2,0.33,0.22]

What could the issue here be????!!!
Please help!!
Im tearing my hair out
Posted by RGraph Support on 10th October 2012
Hi,

This:

"[2,0.33,0.22]"

is a string. ie text. Just because it happens to look like an array makes no odds. You should lose the double quotes - so it looks like this:

[2,0.33,0.22]
Posted by jeremy on 16th October 2012
try the javascript function JSON.parse on your json encoded php array.

Add a reply




« Back to message list