I have an AJAX request on a php file, which returns some data, like this:
21-12-12:::visits;45;;pageviews;344—22-10-10:::visits;71;;pageviews;34—15-01-11:::visits;4;;pageviews;30
Notice the pattern^^ It’s like a multidimensional array, but only not an array, just a string.
I need a way to separate that string, and use the value of visits and pageviews for each date.
I already know how to split the string up in JQuery, but i have no idea how to get the value of visits for a specific date from that string, example, get the number of visits for the date 15-01-11.
Any suggestions or better alternatives would be great. Please don’t mention JSON though, I’ve just given up with that.
Thanks
JSON is the alternative and extremely easy since you are using PHP and jQuery. Actually, everything else would be either a huge mess (parsing a string like you want to do) or much more complicated (using XML instead of JSON).
In your PHP code you simply
echo json_encode($arrayWithYourData);and the response argument of your AJAX success callback will contain the same object.Since you want to get data for a certain date, you might want to use the data as the array key – then you can just use e.g.
response['01-01-01']to access the corresponding array element.