views:

1837

answers:

7

Hi all,

I have a web application that uses the current version of JQuery that needs to get some JSON objects back from a REST web service. I'm using the following call to $.getJSON:

$.getJSON("http://localhost:17245/Service.svc/?format=json", function(data) {alert(data.id);});

This call works fine in IE7 and I can call the service with no problem in Fiddler. I've stepped through this in Firebug, but when Firefox gets to this line the javascript execution just seems to "die" with no error, no call back, no nothing.

I've also used $.ajax and have the same issue; works fine in IE, nothing in Firefox.

Anyone have any ideas? I'm VERY new to JQuery, so please be gentle.

Thanks, James

+4  A: 

I had a similar issue. The signature $.getJSON is (url, data, callback) and I was not passing the data argument either. Try this:

$.getJSON("http://localhost:17245/Service.svc/?format=json", {}, function(data) {alert(data.id);});
palehorse
A: 

I was running into problems using web services from jQuery for a while until I found the ajaxdotnet plugin.

Ariel
A: 

Make sure you're handling ajaxError, otherwise you'll never see the reply if the server returns an error.

Your call to getJSON seems to be missing the data argument, as palehorse says. I usually pass null for this when I don't need it.

Craig Stuntz
If you're running firebug the error should show up. The Net panel can then be used to view the returned headers.
Soviut
A: 

If you can't get JQuery to work, try Fork. Look at Fork.Ajax and Fork.Json. Or use Doug Crockford's json2.js for parsing JSON, with whatever XMLHttpRequest wrapper you like. I looked around at various Javascript libraries a while back and for the most part they were just too bloated and weird for me; you have to learn all the little quirks of the libraries.

Jason S
A: 

I just ran into this problem and found that the root cause was a trailing comma in the JSON that's getting returned.

Ted Naleid
A: 

I saw similar issues due to a bug in the Firebug extension. Try disabling it if you have it installed.

+1  A: 

Not sure if it was ever solved, but it looks like cross site scripting restrictions in Firefox. It treats port numbers on your development ASP.NET server (localhost:0000) as different domains. Try to host both: service and the web application, on IIS which doesn't use port numbers.

vwemil
I have the same problem and I think you're correct. In the Firebug Net panel it doesn't do a GET, it does an OPTIONS. Hence I think I need to figure out how CORS (Cross Origin Resource Sharing) works.
Matt Frear