I am trying to make an ajax call and it returns something like, a JSON object;
{
id: 6,
success: "true"
}
My ajax call is :
window.foobar = function(foo){
$.ajax({
url: "http://foobar.com/sites/foo/",
dataType: "jsonp",
success: function (data) {
alert(data);
},
error: function () {
}
});
}
This ajax call is cross site call.
On chrome it gives: Uncaught SyntaxError: Unexpected token :
On firefox it gives:
invalid label
http://localhost:8080/sites/foo/?callback=jsonp1324336100888&_=1324336100894
Line 1
But when I calling from the same domain it works fine.
If you are claiming to support JSONP, you need to actually support it. Your code is valid JSON, but it is not valid Javascript: a response to a JSONP request must be valid Javascript. (To be precise, your code is invalid because the
{}delimit a block, rather than an object literal.)If you implement JSONP, you need to wrap the data in a call to a function whose name is given in the URL, in the
callbackparameter. So in this case, you need to post the following code:Obviously the precise name of the function you need to call depends on the
callbackURL parameter.