Reputation: 2186
I have this url
call. the url returns a json object as expected (direct browser call) but when I do that via ajax with the follow lines
$.ajax({
url: url,
type: "GET",
dataType:"jsonp",
success: function(data) {
alert(data);
},
error : function(error) {
alert("no good "+JSON.stringify(error));
}
});
it returns me
no good {"readyState":4,"status":200,"statusText":"success"}
I know there's others similar questions on stackoverflow, but nobody seems solved it.
Upvotes: 18
Views: 38798
Reputation: 478
I've just had the exact same issue,{"readyState":4,"status":200,"statusText":"success"}
it was because I forgot to remove in my php script an echo "hello"; statment which I previously made for testing reasons, so my php script was sending a string along with JSON, that was my silly mistake maybe You have got the same too
Upvotes: 1
Reputation: 2186
these changes solved my problem.
//Server side
echo $_GET['callback'] . '('.json_encode($data_to_encode).')';
//js
$.ajax({
url: url+"?callback=?",
type: "GET",
dataType:"jsonp",
success: function(data) {
alert(data);
},
error : function(error) {
alert("no good "+JSON.stringify(error));
}
});
Upvotes: 5
Reputation: 943686
That suggests that the HTTP request was successful but the attempt to parse the data was not.
i.e. that the data was not formatted as JSONP.
Upvotes: 37