开发者

AJAX sending json data as text/xml

I have two sites using the same javascript code to interact with several web services. The code works perfectly in one site, but in the other, it is sending the data as text/xml. I have looked at the web config files in both sites and cannot spot anything that could cause the difference. The AjaxControlToolkit DLL files are the same. The AJAX call fails with an error 500 because the data is not in the proper form.

Code that makes the AJAX call:

function displaySessionNotifications() {
$.ajax({
type: "POST",
async: false,
url: "NotificationService.asmx/ListSessionNotifications",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({}),
success: function (data) {
$list = JSON.parse(data.d);
if (window.console.log) { window.console.log('Notification Service Msg Cnt: ' + $list.length) };
for (var i = 0; i < $list.length; i++) {
displayMessage($list[i].MessageText, $list[i].MessageType, $list[i].IsSticky, $list[i].jGrowlClass, $list[i].ContainerId);
};
if ($list.length > 0) {
clearSessionNotifications($list[0].SessionId);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("NotificationService/ListSessionNotifications failed: " + XMLHttpRequest.responseText);
}
});
} 

Watch Data from Firebug:

this Object { url="NotificationService.asmx/ListSessionNotifications", global=true, type="POST", more...}

XMLHttpRequest
    Object { readyState=4, status=0, statusText="error"}

errorThrown
    [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js :: <TOP_LEVEL> :: line 16" data: no] { name="NS_ERROR_FAILURE", message="Component returned fail...4005 (NS_ERROR_FAILURE)", result=2147500037, more...}

textStatus
    "error"

Firebug console display of the code that works:

Server  ASP.NET Development Server/10.0.0.0
Date    Wed, 21 Sep 2011 17:44:39 GMT
X-AspNet-Version    4.0.30319
Cache-Control   private, max-age=0
Content-Type    application/json; charset=utf-8
Content-Length  10
Connection  Close
Request Headers
Host    127.0.0.1:54837
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept  application/json, text/javascript, */*; q=0.01
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
Connection  keep-alive
Content-Type    application/json; charset=utf-8
x-requested-with    XMLHttpRe开发者_如何学JAVAquest
Referer http://127.0.0.1:54837/WebSite/TestNotifications.aspx
Content-Length  2
Cookie  JXID=80VR2F3uNRgK8YteuGgnAbsR; JXHID=false; Identifier=Id=20c8b636-7ec4-464f-b6dc-867d0924f475; enhanced=pass; Skin=Default; ASP.NET_SessionId=3nientky4k1hdy3gkfemne04; linkedin_oauth_BW-FUQKDybTn3R7TmZ-gHFmiFpzKY9ztqInF8jLVbHwNNkm_iSnIii26jEJts4wI_crc=null

Same data for code that fails:

Response Headersview source
Server  ASP.NET Development Server/10.0.0.0
Date    Wed, 21 Sep 2011 18:34:01 GMT
X-AspNet-Version    4.0.30319
Cache-Control   private
Content-Type    text/html; charset=utf-8
Content-Length  4516
Connection  Close

Request Headersview source
    Host    127.0.0.1:60391
    User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
    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
    Connection  keep-alive
    Origin  http://localhost:60391
    Access-Control-Request-Me...    POST
    Access-Control-Request-He...    content-type,x-requested-with
    Pragma  no-cache
    Cache-Control   no-cache
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜