I really need help on this one. I've been looking at it for hours and been getting nowehere. I am working with ajax in WordPress and this is kind of my first time doing so.
I have a function in my code that utlimately ends with the following:
echo json_encode($aData);
I then have code in my js file written as follows:
jQuery.ajax({
url: "path/to/admin-ajax.php", //AJAX file
// dataType: 'json',
type: 'POST',
// contentType: 'application/json',
data: { action: "process_chart_data" },
success: function(chartData) {
//Code, that need to be executed when data arrives after
// successful AJAX request execution
console.log("SUCCESS");
console.log(chartData);
}
});
You will notice the comments in the above code. When I view chartData in the console I get this:
{"title":"R=3+","dates":["06\/04\/2014","11\/05\/2014","15\/06\/2014","27\/07\/2014","17\/08\/2014","28\/09\/2014","05\/10\/2014","19\/10\/2014","09\/11\/2014","23\/11\/2014","14\/12\/2014"],"series":[{"data":[[1396738800000,284],[1399762800000,350],[1402786800000,212],[1406415600000,296],[1408230000000,220],[1411858800000,253],[1412463600000,200],[1413673200000,310],[1415491200000,180],[1416700800000,156],[1418515200000,290]],"name":"Bulls"}]}0
However when I uncomment the dataType and contentType this outputs a 0.
My issue is I am trying to access properties of the returned array such as chartData.title but all I get is 'undefined'.
I have looked at this from a few different approaches but after a few hours I have had to throw my hands up. I would be greatly appreciative for any assistance people might be able to provide here.