Javascript XMLHTTPRequest不能与IIS集成模式一起使用
在经典模式下运行代码时效果很好……但在集成模式下运行时失败 代码如下:-Javascript XMLHTTPRequest不能与IIS集成模式一起使用,javascript,.net,ajax,iis,iis-7.5,Javascript,.net,Ajax,Iis,Iis 7.5,在经典模式下运行代码时效果很好……但在集成模式下运行时失败 代码如下:- function callAjax(method, request, callback) { http = newHTTP(); http.open('POST', url, true); setupHeaders(http, method); http.onreadystatechange = function () { http_onreadystatechange(http, call
function callAjax(method, request, callback) {
http = newHTTP();
http.open('POST', url, true);
setupHeaders(http, method);
http.onreadystatechange = function () { http_onreadystatechange(http, callback); }
http.send(JSON.stringify(request));
return request.id;
}
function newHTTP() {
if (typeof (window) != 'undefined' && window.XMLHttpRequest)
return new XMLHttpRequest(); /* IE7, Safari 1.2, Mozilla 1.0/Firefox, and Netscape 7 */
else
return new ActiveXObject('Microsoft.XMLHTTP'); /* WSH and IE 5 to IE 6 */
}
function http_onreadystatechange(sender, callback) {
if (sender.readyState == /* complete */4) {
var response = sender.status == 200 ?
JSON.parse(sender.responseText) : {};
response.xmlHTTP = sender;
callback(response);
}
if (sender.readyState == 2 || sender.readyState == 3) {
}
}
function setupHeaders(http, method) {
http.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
http.setRequestHeader('X-JSON-RPC', method);
}
在经典模式下运行时,返回以下响应:-
"{"id":0,"result":{"serverInfo":{"totalCount":2,"serviceName":"FluorineFx.PageableResult","version":1,"cursor":1,"id":null,"columnNames":["ApplicationId","ApplicationParentID","ParentApp","ChildApp"],"initialData":[[1158,1153,"Apps","App_Application1"],[3159,3161,"Databases","DB_Database1"]]}}}"
鉴于,在集成模式下运行时,返回以下信息:-
"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="xxxxx...." id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEXXXXLTE2MTY2ODcyMjlkZLGuNeIyaZaly9gcTafYavVTQG2payFqxE2OaB+1PjxT" />
</div>
<div>
</div>
</form>
</body>
</html>
"
我的问题是,为什么它在集成模式下运行时会返回奇怪的响应?需要调查的是服务器端。它从客户端发送什么内容类型的头?@akonsu同一服务器端可以很好地处理classic,只有一个简单的方法返回datatable。。。。不是很高保真的代码…它随请求发送什么内容类型?@akonsu请查看方法名称-setupHeaders(),可能它不喜欢您发送的标题。如果改为发送application/x-www-form-urlencoded而不发送jsonrpc头,会发生什么情况?
var response = sender.status == 200 ?
JSON.parse(sender.responseText) : {};