I'm sending an AJAX post request to a php script on my server, the server returns the data in JSON format. When I try and alert the results I get the following error: Uncaught SyntaxError: unexpected token { twice.
Here is my AJAX call:
var articles = $.post("process/get_articles.php"); articles.done(function(data){ var result = $.parseJSON(data); alert(result); }); My server side code:
while($query->fetch()){ $result = array("ID"=>$Art_number, "Article"=>$Article, "Image"=>$Image_link); $result = json_encode($result); echo $result; } which returns the following:
{"ID":1,"Article":"Article 1","Image":"http:\/\/wwww.mydomain.com\/images\/img.jpg"}{"ID":2,"Article":"Article2","Image":""}{"ID":3,"Article":"Article 3","Image":""} Why is the data returned not properly alerted? Any help is greatly appreciated!