0

I've been banging away at this problem most of the day and I'm just stumped.

I have a .NET webservice that returns a JSON serialized response and am trying to switch it out with a new one that has access to more data to serialize. Both of the services look identical as far as their logic for handling requests. both set the ContentType to application/json and write to the stream.

I'm using jQuery 1.7.1 On the client side, I send the getJSON off with the URL to the working endpoint. Firebug shows the result coming back, full of data and it validates out in JSONLint and others. I set up a .ajaxSetup() to catch the onError event and I get this:

textStatus: parsererror
Error Thrown: Error: jQuery17109478366139694514_1337880510219 was not called
jqXHR Response Text: undefined

(i formatted the message)

The JSON I'm looking at is a bunch of this:

[
    {
        "sourceType": "KML",
        "dataUrl": "http://firefly.geog.umd.edu/kml/download.php?file=kml_global_modis-hotspots.kml",
        "id": "https://example.com/KmlFeeds::KMLFeeds::FIRMS::World",
        "title": "FIRMS - World",
        "description": "MODIS hotspot / fire and burned area",
        "originator": "NASA LANCE",
        "spatialDomain": null
    },
    {
        "sourceType": "KML",
        "dataUrl": "http://firefly.geog.umd.edu/kml/download.php?file=Alaska_24h.kml",
        "id": "https://example.com/KmlFeeds::KMLFeeds::FIRMS::Alaska",
        "title": "FIRMS - Alaska",
        "description": "MODIS hotspot / fire and burned area",
        "originator": "NASA LANCE",
        "spatialDomain": null
    },
...
]

(spatialDomain sometimes has bounding box coordinates, just comma separated decimals in a string)

My old web service returns the same with a couple of the keys differently labeled. Using the new service I never get to the callback which posts all of this data to the site. It's definitely coming back to me and looks valid anyway I look at it.

I want to think there is something off with the new service - if I just switch the request URL back to the old one my client works just fine. However the response is coming back as valid JSON so I can't figure out how it's having issues just getting into the success callback. Thoughts?

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539

1 Answers1

2

It looks like jQuery is expecting a JSONP web service, but the server is not correctly calling the JSONP callback.

Post your getJSON call. Also, can you post the domains of the page calling getJSON and web service (mask them out if necessary) so we can see if it's cross-domain.

EDIT: It looks like it does have to be cross-origin, since different ports on the same server are considered cross-domain. So that means you want to use JSONP. The problem seems to be that your new service is not correctly serving JSONP (probably it is serving JSON). You should look at the difference in configuration between the old and the new.

Community
  • 1
  • 1
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • Sure thing: `jQuery.getJSON(jsonUrl+"&callback=?", jsonSourcesReceived);` My old service actually is cross domain: `http://PRIVATE/KmlFeeds/kmlcatalogservice.ashx` The new one is localhost since I'm trying to develop it some more `http://localhost:61202/DataCatalogService/datacatalogservice.ashx?op=getdatasources&includetypes=kml&format=json` – zacharykane May 24 '12 at 19:40
  • @ZacharyKanePride, is that the same `localhost` domain that's calling `getJSON`? Also, will it be cross-domain in production? – Matthew Flaschen May 24 '12 at 19:43
  • The possibility is definitely there. Right now the localhost hosting the datacatalogservice is the same one hosting my client, just different ports, for the moment. – zacharykane May 24 '12 at 20:04
  • The thing is, the old service (at PRIVATE) is on a different server. I've been using the getJSON() to get that response and it's been working just fine. I'm assuming another method/logic should be necessary in a cross domain situation? – zacharykane May 24 '12 at 20:18
  • @Zachary, so I think it does have to be JSONP, and it's not. Look at the differences between the two services (server-side code and configuration). – Matthew Flaschen May 24 '12 at 21:15
  • @Zachary, if it's valid JSONP, it will look like the JSONP example on [this page](http://developer.echonest.com/raw_tutorials/responses.html) but with a different function name. – Matthew Flaschen May 24 '12 at 21:21
  • Aha! The new service was missing the call back wrapper option `output = options.callbackParam + "(" + output + ")"; Added and now I'm in business! Thanks a lot Matthew-I was going crazy skimming these service configs. – zacharykane May 25 '12 at 15:04