通过写 location.href 或者 xmlhttp.open() 都可以发起 get 请求

解决方案 »

  1.   

    var http = new ActiveXObject("Microsoft.XMLHTTP");
    http.open("Get","页面.asp?id=1",false);
    http.send();
    alert(http.responseText);//执行结果。
      

  2.   

    <script language="VBScript" >
    //解决中文显示问题
    Function bytes2BSTR(vIn)
    Dim strReturn,i,ThisCharCode,innerCode,Hight8,Low8,NextCharCode
    strReturn = ""For i = 1 To LenB(vIn)
     ThisCharCode = AscB(MidB(vIn,i,1))
     If ThisCharCode < &H80 Then
      strReturn = strReturn & Chr(ThisCharCode)
     Else
      NextCharCode = AscB(MidB(vIn,i+1,1))
      strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
      i = i + 1
     End If
    Next
    bytes2BSTR = strReturn 
    End Function
    </script><script language="javascript">
    function XHConn()
    {
      var xmlhttp, bComplete = false;
      try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
      catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e) { try { xmlhttp = new XMLHttpRequest(); }
      catch (e) { xmlhttp = false; }}}
      if (!xmlhttp) return null;
      this.connect = function(sURL, sMethod, sVars, fnDone)
      {
        if (!xmlhttp) return false;
        bComplete = false;
        sMethod = sMethod.toUpperCase();    try {
          if (sMethod == "GET")
          {
            xmlhttp.open(sMethod, sURL+"?"+sVars, true);
            sVars = "";
          }
          else
          {
            xmlhttp.open(sMethod, sURL, true);
            xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
            xmlhttp.setRequestHeader("Content-Type",
              "application/x-www-form-urlencoded");
          }
          xmlhttp.onreadystatechange = function(){
            if (xmlhttp.readyState == 4 && !bComplete)
            {
              bComplete = true;
              fnDone(xmlhttp);
            }};
          xmlhttp.send(sVars);
        }
        catch(z) { return false; }
        return true;
      };
      return this;
    }//回调函数
    var fnWhenDone = function (oXML) {
            alert(bytes2BSTR(oXML.responseBody));
    }
    var myConn = new XHConn();
    myConn.connect("http://www.baidu.com/s", "GET", "ct=0&ie=gb2312&bs=xmlhttp&sr=&z=&cl=3&f=8&wd=xmlhttp+%D6%D0%CE%C4", fnWhenDone);
    </script>
      

  3.   

    var obj;
    obj = new ActiveXObject("MSXML2.XMLHTTP");
    if(!obj){
      obj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    obj .open("GET","url",false);
    obj .send();
    //obj.responseText为返回的内容