AJAX以text / xml的形式发送json数据

时间:2011-09-21 18:51:47

标签: ajax json

我有两个网站使用相同的JavaScript代码与多个网络服务进行交互。代码在一个站点中完美运行,但在另一个站点中,它以text / xml格式发送数据。我查看了两个站点中的Web配置文件,但无法发现可能导致差异的任何内容。 AjaxControlToolkit DLL文件是相同的。 AJAX调用因错误500而失败,因为数据格式不正确。

进行AJAX调用的代码:

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);
}
});
} 

观看Firebug的数据:

此     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控制台显示有效的代码:

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    XMLHttpRequest
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

代码失败的相同数据:

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 个答案:

没有答案