I am really lost here, and I have no idea what I am doing wrong.
I have exposed an api which gives a json output, and I want to fetch this data from another domain. Since jsonp is way to go, I am trying the code below.. Inspection on firebug shows that the response to the request is proper JSON, but the callback functions never seem to execute. Any help?
$(function(){
console.log('aa');
$.ajax({
url: 'http://domain/api.php',
data: {f:'get_total_playtime',userid:'1',starttime:'2011-01-01',endtime:'2011-12-12'},
dataType: 'jsonp',
success: function(data){
console.log('suceess');
alert(data.time);
},
failure: function(data){
console.log('failure');
}
});
});
If this is not the right way to go about it, can anyone explain the right way?
Then that is the problem. You have to return JSONP, not JSON.