2

在经典模式下运行代码工作正常......但在集成模式下运行时失败。

这是代码: -

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>

"

由于上述响应,它在这一行的 http_onreadystatechange() 方法内失败:-

var response = sender.status == 200 ?
JSON.parse(sender.responseText) : {};

我的问题是为什么它在集成模式下运行时返回奇怪的响应?

4

0 回答 0