RGraph.AJAX.POST needs to convert string to object

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 Vicente Herrera on 7th August 2013
I've stubled with this for a while, note that when using AJAX.getJSON, the data is provided to the callback function as an object:

...
RGraph.AJAX.getJSON(base_url, drawGraphAjax);
...
function dragGraphAjax(data) {
   //data is object
}


But when using RGraph.AJAX.POST, the data is provided as an string that needs to be converted to object:

...
RGraph.AJAX.POST(base_url,filters,drawGraphAjax);
...
function dragGraphAjax(data) {
   //data is string
   data = eval('(' + data + ')');
   //now data is object
}




Posted by RGraph support on 7th August 2013
Hi there,

The response to an AJAX POST request is not necessarily a JSON object - it could be a HTML page for example just like when you're submitting an online form.

What you'e doing now (eval()ing the response) is really the correct way - since you know what your response should be. If I were to change the POST function it would be a big assumption that every bodies responses to their POST request is a JSON object.


Richard, RGraph Support

Help support RGraph - single site license only £99
   www.rgraph.net/license#single-site
Posted by Vicente Herrera on 7th August 2013
Thanks Richard, you're right.

It would be nice for other users if you write this explanation on the RGraph.AJAX.POST documentation also. Maybe someone else hasn't realised it also.

Thanks for such an excellent library, keep up the good work! ;-)

Add a reply




« Back to message list