function GetInf() {
    var code = $("#code0").val();//参数
    var xmlHttp;
   if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
    xmlHttp.open("GET", "http://119.145.12.180/anta/Service/GetFlowcodeInfo?flowcode=" + code, true);
    var str = xmlHttp.responseText;//提取不出东西,为空
    var a = unescape(xmlHttp.responseText);//提取不出东西,为空
    xmlHttp.send(null);
}
我想问我这个哪里错了,为什么我提不出东西。
有谁有好的办法用ajax或者jquery抓取远程网页的内容。
我使用的语言是asp.netxmlhttprequestasp.netjqueryajax

解决方案 »

  1.   

    方法用错了,建议用jquery的ajax方法,封装的很好
      

  2.   

    jquery是不允许跨域读取文件的。
    你可以先把远程文件下载到本地,然后再用jquery进行加载。
      

  3.   

    默认好像是不能跨域的。看看这篇文章:
    Making cross domain JavaScript requests using XMLHttpRequest or XDomainRequest
    http://www.leggetter.co.uk/2010/03/12/making-cross-domain-javascript-requests-using-xmlhttprequest-or-xdomainrequest.html
      

  4.   

    <html>  
    <head>  
    <title>Ajax Sample</title>  
    <script type="text/javascript">  
    var xmlHttp=null;   
    try   
    {   
        xmlHttp=new XMLHttpRequest();   
    }   
    catch (e)   
    {   
        try   
        {   
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");   
        }   
        catch (e)   
        {   
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
        }   
    }   
      
    function makerequest(serverPage,objId)   
    {   
        var obj = document.getElementById(objId);   
        xmlHttp.open("GET", serverPage);   
        xmlHttp.onreadystatechange = function()    
        {   
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200)    
            {   
                obj.innerHTML = xmlHttp.responseText;   
            }   
        }   
        xmlHttp.send(null);   
    }   
    </script>  
    <body onLoad="makerequest ('content1.html','hw')">  
        <div align="center">  
            <h1>My Webpage</h1>  
        <a href="content1.html" onClick="makerequest('content1.html','hw'); return false;">Page 1</a>    
        <a href="content2.html" onClick="makerequest('content2.html','hw'); return false;">Page 2</a>    
        <a href="content3.html" onClick="makerequest('content3.html','hw'); return false;">Page 3</a>    
        <a href="content4.html" onClick="makerequest('content4.html','hw'); return false;">Page 4</a>  
        //这里就是将要替换content1~4.html的位置。   
            <div id="hw"></div>  
        </div>  
    </body>  
    </html>    
      

  5.   


    不能跨域的,别费这个心了。
    有研究跨域的时间 还不如写个后台抓取页面 保存到本地 然后再用jquery解析。
      

  6.   

    看下这篇文章  利用jsonp是可以的
    深入浅出JSONP--解决ajax跨域问题
      

  7.   


    这个能返回网页吗?dataType只能指定dataType:"jsonp"
      

  8.   

    IE8,XDomainRequest对象可以跨域,不过远程需要设置头部字段
      

  9.   

    哦哦  抓网页的话jsonp貌似还不行  我再研究下看看