Why is this JSONP feed throwing “Unexpected Token” error?

I'm trying to grap this remote JSONP feed via jQuery.

Every time I try, I get an error of "Uncaught SyntaxError: Unexpected token (" or similar.

Am I doing something wrong or is something in the JSONP data formatted/escaped incorrectly?

Fiddle: http://jsfiddle.net/callmeed/d3tSX/2/

var _event_url = "http://calvaryslo.onthecity.org/plaza/*events*?format=json";
$.ajax({
    type: 'GET',
    url: _event_url,
    dataType: 'jsonp',
    success: function(msg) {
        alert(msg.length);
    }
});?

Answers:

Answer

Because this feed returns JSON, not a javascript function call:

[{Query172031345640518702567_1334079878875({...

But it should be:

Query172031345640518702567_1334079878875({...

I don't know if this service is under your control and you can changed it, or you just need to add some params to the URL (check the manual).

Also the content type of the response should be application/javascript, not text/json.

Answer

If you use dataType: 'jsonp' JQuery appends a callback url parameter to the request. The value of this parameter must be the function name of the callback function the server returns. As Eugene Retunsky already mentioned this is formatted incorrectly, also it seems that the server code is omitting the first character of the function name so jQuery_674... becomes Query_674... which will not work.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.