GetJSON works on IE 7 but not Firefox 3

I have a web application that uses the current version of jQuery, which should return some JSON objects from a REST web service. I use 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 without problems in Fiddler. I went through this in Firebug, but when Firefox gets to this line, javascript execution just seems to be "dying" without errors, without a callback, nothing.

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

Does anyone have any ideas? I am VERY new to jQuery, so please be careful.

Thanks James

+4
source share
7 answers

I had a similar problem. The $ .getJSON signature is (url, data, callback), and I also did not pass the data argument. Try the following:

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

Not sure if it has ever been resolved, but it looks like restrictions on the use of scripts in Firefox. It treats the port numbers on your ASP.NET development server (localhost: 0000) as different domains. Try hosting both the service and the web application in IIS, which does not use port numbers.

+1
source

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

0
source

Make sure you handle ajaxError , otherwise you will never see the answer if the server returns an error.

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

0
source

If you can't get jQuery to work, try Fork . Take a look at Fork.Ajax and Fork.Json. Or use Doug Crockford json2.js to parse JSON with any XMLHttpRequest shell used. I looked around the various Javascript libraries for a while, and for the most part they were too bloated and strange for me; You should study all the small quirks of libraries.

0
source

I just ran into this problem and found that the main reason was the trailing comma in JSON, which is being returned.

0
source

I saw similar problems due to a bug in the Firebug extension. Try disabling it if it is installed.

0
source

All Articles