1
votes

I have developed a mobile site which consumes a JSON service. I consume JSONP as it's cross-domain. It was working and suddenly broke, and I cannot fathom why. Here is what I can inspect in the browser:

My Javascript Call:

$.ajax({
url: apiBaseURL + "getoperators?appKey=" + appKey,
dataType: 'jsonp',
success: function(data) {
    console.log(data);
},
    error: function(jqXHR, textStatus, errorThrown) {             }
});

When I view the response it seems correctly formed as below:

{"GetOperatorsResult":{"Error":"","Results":[{"City":"Cape Town","IsPublic":true,"Mode":"Bus","Name":"Golden Arrow"},{"City":"Cape Town","IsPublic":true,"Mode":"Shuttle","Name":"Jammie Shuttle"},{"City":"Cape Town","IsPublic":true,"Mode":"Train","Name":"Metrorail"},{"City":"Cape Town","IsPublic":true,"Mode":"Bus","Name":"MyCiti"}],"Status":"Success"}}

Here is the Network Audit:

Request URL:http://api.wimt.co.za/v1/json/public.svc/getoperators?appKey=EB478338-73C7-483F-8AB4-B4DE2219D4DC&callback=jQuery18208015921225305647_1350479608882&_=1350479608950 Request Method:GET Status Code:200 OK Request Headersview source Accept:/ Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Host:api.wimt.co.za Referer:http://localhost:8300/index.html User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4 Query String Parametersview URL encoded appKey:EB478338-73C7-483F-8AB4-B4DE2219D4DC callback:jQuery18208015921225305647_1350479608882 _:1350479608950 Response Headersview source Content-Length:353 Content-Type:application/json; charset=utf-8 Date:Wed, 17 Oct 2012 13:13:43 GMT Server:Microsoft-IIS/7.5 X-Powered-By:ASP.NET

We are 1 day before launch and something which was working perfectly has broken and I cannot for the life of me work out what. The error could be in the web.config, but I have all the right headers/endpoints there.

Someone please help. Thank you!

1
At what position do you you get the error?Rune FS
It goes in the error function as oppossed to success. I receive the following response: Error: jQuery18208741367822512984_1350482142524 was not called parsererror [object Object]user1434739
Yes and at what position do you get the parsing error? I'll assume it is the first character and he DD has already posted the answerRune FS

1 Answers

2
votes

It seems that the remote API no longer sends JSONP but plain JSON. In a valid JSONP call the response must be wrapped in the callback name:

jQuery18208015921225305647_1350479608882({"GetOperatorsResult":{"Error":"","Results":[{"City":"Cape Town","IsPublic":true,"Mode":"Bus","Name":"Golden Arrow"},{"City":"Cape Town","IsPublic":true,"Mode":"Shuttle","Name":"Jammie Shuttle"},{"City":"Cape Town","IsPublic":true,"Mode":"Train","Name":"Metrorail"},{"City":"Cape Town","IsPublic":true,"Mode":"Bus","Name":"MyCiti"}],"Status":"Success"}})

You should contact the owner of the API or read the documentation in order to understand how to specify a JSONP call.