无法通过XMLHttpRequest发送参数字符串

Unable send the parameter string through XMLHttpRequest

本文关键字:参数 字符串 XMLHttpRequest      更新时间:2023-09-26

你好,我试图从Web服务获得响应,但当我通过XMLHttpRequest.send(params)方法发送请求参数时,请求参数没有被发送。

下面是我的代码:
<script type="application/javascript">
window.onload = function myFunc()
{
    var httpRes;
    if (window.XMLHttpRequest)
    {   
        httpRes=new XMLHttpRequest();
    }
    else
    { 
        httpRes=new ActiveXObject("Microsoft.XMLHTTP");
    }   
    httpRes.open("POST", "http://192.168.11.59:3333/Reports/GenerateMobReportJsonData", true);  
    var params = {'FromDate':'02/19/2013 17:30','ReportId':'1','LocationId':'1','ToDate':'02/19/2013 19:00','TeamId':'1'}
    httpRes.setRequestHeader('content-type', 'application/json');
    var jsonReq = JSON.stringify(params);
    //alert(jsonReq)
    httpRes.send(jsonReq);
}
</script>

由于您使用'Application/Json'作为您的通信协议,并且您的jquery托管服务器和web服务服务器不同,因此可能存在CrossDomain请求

的问题

这里应该使用Jsonp作为通信协议。

下面是一个例子-

http://www.jquery4u.com/json/jsonp-examples/

两个不同服务器之间的请求应该使用jsonp协议。

这里也有类似的问题-

jQuery Ajax即使在HTTP 200状态下也失败