zoukankan      html  css  js  c++  java
  • ajax获取url数据

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>jQuery EasyUI</title>
    <link rel="stylesheet" type="text/css"
        href="../themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../themes/icon.css">
    <script type="text/javascript" src="../jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="../jquery.easyui.min.js"></script>
    <script>
    function getXmlHttp() //获取XMLHttpRequest对象  
        {  
            if(window.XMLHttpRequest)  
            {    
                return new XMLHttpRequest();
            }  
            else 
            {         
                return new ActiveXObject("Microsoft.XMLHTTP"); //针对IE浏览器
            }  
         } 
    function getInfo(type,startDate,endDate,pagingIndex) //根据给进的参数请求服务数据
        {
            var url="http://localhost/jquery-easyui-1.3.1/waf/test.html"; //拼接地址
            xmlHttp=getXmlHttp();                     //得到XMLHttpRequest对象
            alert(xmlHttp.readyState);
            xmlHttp.open("GET", url, true);            //打开连接
            alert(xmlHttp.readyState);
            console.info(xmlHttp);
             xmlHttp.onreadystatechange=function ()        //定义当信息反馈回来时的处理函数 状态信息发生变化时执行的函数
             {    
                
                 if(xmlHttp.readyState==4)
                {
                    alert(xmlHttp.responseText);     //将得到的信息弹出来
                }
             };
              xmlHttp.send();                     //发送请求
        }
    function getInfos(type,startDate,endDate,pagingIndex) //根据给进的参数请求服务数据
        {
            var xmlHttpReq = new XMLHttpRequest(); 
            xmlHttpReq.open("GET", "http://localhost/jquery-easyui-1.3.1/waf/test.html", false);//第三个参数,布尔型求指指指请求求求为异步求方求方认为true。方。为真求当当态改变变会调用onreadystatechange属性指指新性调函数。
            xmlHttpReq.send();
            alert(xmlHttpReq.responseText);
        }    
        </script>
    </head>
    <body>
    <h1>request</h1>
    <input type="button" onclick="getInfo()" value="确定">
    </body>
    </html>

    url是不能跨域的···今天才知道!!!如果想跨域,将浏览器的安全设置改一下就行了

  • 相关阅读:
    Golang 函数
    关于Golang中database/sql包的学习
    golang第三方库goconfig的使用
    golang []byte和string相互转换
    golang xorm应用
    PHPExcel 导入
    贝叶斯定理
    myFocus 焦点图/轮播插件
    Maven 安装与使用(一)
    Javascript -- toFixed()函数
  • 原文地址:https://www.cnblogs.com/qingxuan/p/2921938.html
Copyright © 2011-2022 走看看