Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AJAX以文本/xml格式发送json数据_Ajax_Json - Fatal编程技术网

AJAX以文本/xml格式发送json数据

AJAX以文本/xml格式发送json数据,ajax,json,Ajax,Json,我有两个站点使用相同的javascript代码与多个web服务交互。该代码在一个站点上运行良好,但在另一个站点上,它以text/xml的形式发送数据。我查看了这两个站点中的web配置文件,但没有发现任何可能导致差异的内容。AjaxControlToolkit DLL文件是相同的。AJAX调用失败,错误为500,因为数据的格式不正确 进行AJAX调用的代码: function displaySessionNotifications() { $.ajax({ type: "POST", async:

我有两个站点使用相同的javascript代码与多个web服务交互。该代码在一个站点上运行良好,但在另一个站点上,它以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);
}
});
} 
失败代码的相同数据:

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

您是否尝试添加processData:false?请查看失败请求标头中的Accepts字符串。
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