I have some code below which sends data to a server and then the server returns results in JSON however the callback for the function is not getting any data when I alert it is comes up as undefined. My code is below
Here in my php web service I encode my array because thats the only way I can get the data from the datatype text column
Code:
$posts[] = array_map('utf8_encode',$post);
When I query the service directly I get this
([{“artist_id”:“14”,“artist_name”:“Nebula 868” etc. etc.
My jQuery code is below and it works except for the callback
var durl = "a valid url";
$.ajax({
type: "GET",
url: durl,
data: "Pass="+avalidid,
dataType: "jsonp",
cache : false,
jsonp : "onJSONPLoad",
jsonpCallback: "callback",
contentType: "application/json",
crossDomain: "true",
}).done(function(){
}).fail(function(){
$.mobile.changePage("errorpage");
})
});
//callback function
function callback(rtndata)
{
alert(rtndata.name);
}
Here is the last few lines of the Web service that returns json
echo $_GET['onJSONPLoad'];
echo "(" . json_encode($posts) . ")";
when I try to alert the json within the callback I get undefined. No clue as to why any what that I can solve this issue?