Ive been trying to parse and display the json data returned by a REST API without success.
Tested locally, the API is of form:
http://localhost/apiurl/get-data.php
And it returns data in form:
[{"title":"Title One","message":"Message One"},{"title":"title two","message":"message two"},....]
Each item consist of two elements ; title and message as shown above.
I want to loop through all returned items and display the result in a div like this
<p>Title One</p>
<p>Message One</p>
Etc.
Ive tried something like this:
<script src="path/to/jquery"></script>
<script type="text/javascript">
$(document).ready(function(){
var url="http://localhost/apiurl/get-data.php";
$.getJSON(url,function(json){
$.each(data,function(i,dat){
$("#resultid").append(
'<p>Title : <em>'+dat.title+'</em>'+
'<p>Message : <em>'+dat.message+'</em></p>'+
'<hr>'
);
});
});
});
</script>
but it didn't work. Any other idea?

jsonvariable after you get it. Does it contain the data you want?