ajax http get

<html>
<head>


<script type="text/javascript" language="javascript">
var xmlHttp;
//创建xmlHttp对象
function createXMLHttpRequest() {
     if (window.ActiveXObject) {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     else if (window.XMLHttpRequest) {
         xmlHttp = new XMLHttpRequest();
     }
 }


function sendRequest(url,HttpMethod) {

  createXMLHttpRequest();//调用创建xmlHttp对象函数
 xmlHttp.open(HttpMethod, url, true);
  xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
  //xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8");
  xmlHttp.setRequestHeader("Host","192.168.1.222");
  xmlHttp.onreadystatechange = processReqChange;//调用进程监视函数
  xmlHttp.send(null);
 
  //alert(xmlHttp.responseText);//这里可以看到接收到是C代码段第二部分
}

function processReqChange() {
  //alert(xmlHttp.readyState);
    // 监视数据传递。
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
           alert(xmlHttp.responseText);       // connect OK 执行输出函数out()
         } else { //抛出错误
            alert("错误:" +xmlHttp.statusText+":"+xmlHttp.status);
         }
    }
}

</script>  
</head>

<body>
    <input type="button" value="CallWebserviceByGet" onclick="sendRequest('http://192.168.1.222:8000/PDAWebService/WebService.asmx/GetCarInfo? HTTP/1.1','GET');">
</body>
</html>

posted @ 2011-11-02 14:19  huangqing  阅读(211)  评论(0)    收藏  举报