I am having a problem with the firefox and chrome when ever i try to do a ajax post. I see that the content length is always 0 in the response and also even after specifying the datatype as 'json' the 'Accept' values in the header are set to the default values. The page works fine in IE8. I haven't checked in other versions though. I am doing a cross domain post to a web service.
currently both the service and the web application reside on the same server.
OPTIONS /JSONWebService/Service1.asmx/GetUserDetails HTTP/1.1
Host: 192.168.0.104
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,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
Access-Control-Request-Method: POST
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Sat, 13 Mar 2010 06:30:27 GMT
X-Powered-By: ASP.NET
MS-Author-Via: DAV
Content-Length: 0
Accept-Ranges: bytes
DASL: <DAV:sql>
DAV: 1, 2
Public: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH
Allow: OPTIONS, TRACE, GET, HEAD, LOCK, UNLOCK
Cache-Control: private
Request and Response for IE8
POST /JSONWebService/Service1.asmx/GetUserDetails HTTP/1.1
Content-Type: application/json; charset=utf-8
Accept-Language: en-us
Accept: application/json, text/javascript, */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)
Host: 192.168.0.104
Content-Length: 21
Connection: Keep-Alive
Pragma: no-cache
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Sat, 13 Mar 2010 06:34:32 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: application/json; charset=utf-8
Content-Length: 243
The ajax method looks as shown below.
$.ajax({
type: "POST",
url: "http://192.168.0.104/JSONWebService/Service1.asmx/GetUserDetails",
data: "{\"tokenNumber\":" + $("#txtTokenNumber").val() + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
var userDetail = eval("(" + msg.d + ")");
alert(userDetail.FirstName);
},
error: function(x, y, z) {
alert(x.responseText);
}
});
if you see the datatype in the above statement its written as JSON. I also get an error when ever i change the datatype to JSONP.
Any help would be appreciated.
Thanks