tags:

views:

93

answers:

2

This piece of javascript always returns null in firefox & chrome, but works fine in internet explorer:

  $.ajax({
    url: "http://mymachine/mywebservice.asmx/myfunction",
    data: "{ 'q': 'hotels', 'limit': '10' }",
    dataType: "json",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    dataFilter: function (data) { return data; },
    success: function (data) {
        alert(data == null);
    }
  });

Looking in fiddler, the IE request looks like this:

POST http://remotemachine/webservice.asmx/functionname HTTP/1.1
Content-Type: application/json; charset=utf-8
Accept-Language: en-gb
Referer: http://localmachine/
Accept: application/json, text/javascript, */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET4.0C; .NET4.0E)
Host: test.maznet.biz
Content-Length: 32
Connection: Keep-Alive
Pragma: no-cache

{ 'q': 'hotels', 'limit': '10' }

The firefox request, running exactly the same javascript, looks like this:

OPTIONS http://remotemachine/webservice.asmx/functionname HTTP/1.1
Host: remotehost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Origin: http://mymachine
Access-Control-Request-Method: POST

Edit: ive amended the exact function names and domains for anonimity, so forgive any typos

A: 

Try going to the URL that you are requesting via ajax directly. Get the full URL of the request (from FireBug in Firefox) and run it there to see what Firefox gets back. Then you can try the same thing in IE via Fiddler. If the URLs are different in any way, you should be able to see what the error is pretty quickly. If they are the same, then loading the URL in each browser should show you differences in the results.

Charles Boyung
Firebug was returning an empty response string, i thought i was going mad! Ive found the answer, and posted it here.
maxp
+1  A: 

Oh my, five hours of working on this, ive just found the answer. Firefox/Chrome will not allow cross domain JSON requests, hence it working in good old slack security IE8, and not in the more 'secure' browsers. Doh!

maxp
Neither will IE, in general.
Pointy