功能目的是读取远程动态内容,做出相应的操作。
举例:读取http://www.baidu.com/1.asp?id=random()
如果读取的返回为1,则alert("OK")
如果读取的返回为0,则alert("Error")网上找了些代码,但是不能跨域。只能读本地function getHttp()
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("GET", "http://www.baidu.com/1.asp?id=random()", false);
xmlhttp.Send();
alert(xmlhttp.responseText);
}
请问那要如何才能实现这样的效果呢?

解决方案 »

  1.   

    要不用服务器端程序读取别人域下面的数据
    再通过ajax访问你服务器端页面(读取数据进行处理的那张页面)
    就是建代理
      

  2.   

    在浏览器中这样用肯定是不行的。不知道在服务器端用node.js行不行
      

  3.   

    http://baike.baidu.com/view/2131174.htm
      

  4.   

    ajax 作用域是不的,只能读本地。都是高手啊,菜鸟路过..
      

  5.   

    //前台代码
     $.ajax({
                url:"http://localhost:8088",
                dataType:"jsonp",
                jsonpCallback:"callback"
            });
    function callback(object){
    //object为值 
    }
      

  6.   

    如何跨域写数据的话,动态Script就实现了,如何跨域读取数据的话,就得用jsonp了!
      

  7.   

    http://192.168.1.2/1.htm<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>jQuery-跨域请求</title>
    <script type="text/javascript" src="jquery.js"></script>
    </head>
    <script type="text/javascript">  
            $(document).ready(function(){  
                $.ajax({  
                    type : "GET",  
                    url : "http://192.168.1.3/jq.asp",  
                    dataType : "jsonp",  
                    jsonp: 'callback',  
                    success : function(json)  
                    {  
                        $('#msg_box').html(json.msg);  
                        return true;  
                    }  
                });  
            });  
        </script>
    <body>
    jQuery-跨域请求:
    <div id="msg_box"></div>
    </body>
    </html>
    http://192.168.1.3/jq.asp<%
    Response.Write "{$callback}({'msg':'this is a jquery jsonp test message!~'})"
    %>
    貌似没成功,哪不对了?
      

  8.   


    <script type="text/javascript" src="jquery.js"></script> 
    <script type="text/javascript">
    $.getJSON('http://192.168.1.3/json.asp?jsoncallback=?',//请求另外一个跨跨域的页面
    function(data){
     alert(data.name)
    });</script><%
    response.write request.querystring("jsoncallback")&"({name:'OK'})"
    %>
    asp文件必须要request回调