I'm trying to make an Ajax call to my server using the following jQuery call:
$.ajax({
type: "GET",
dataType: "jsonp",
url: "http://iceworld.sls-atl.com/api/&cmd=time",
success: function (data) {
console.log("success");
console.log(data);
},
error: function (error) {
console.log("error");
console.log(error);
},
});
I get the data that I expect from the browser, but Firebug keeps saying "SyntaxError: invalid label" as shown below:

So, what puzzles me is the reason why the error callback is called instead of success. I'm wondering what I did wrong here.
JSONP data must be returned in the format: callback( jsonObject ). That is why you are getting an invalid label error. It is expecting a function, not a JSON object. You need to modify your server code to wrap the return value with the name of the callback function. The name is automatically added to the request by jQuery when you request JSONP. If you watch the request, you should see something like this:
http://iceworld.sls-atl.com/api/&cmd=time?callback=jQuery191035087670385837555_1365126604422&_=1365126604423
Your script needs to take the callback parameter and use that to wrap the data, so for this example it would look like this:
jQuery191035087670385837555_1365126604422({"status":1,"data":"1365126534"})
If you are accessing the server from the same origin, you could simply use JSON instead.
It's hard to clearly answer without more details and without the response sent by the server. But looking at this, it looks like the server is returning valid JSON; not a JSONP wrapper function. Try to change the dataType to JSON (no promise though, would need more info to be sure)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With