• ajaxs


    <?php 
    header("Content-Type:text/html; charset=utf-8");
    ?>
    <html>
    <script type="text/javascript">
    function loadXMLDoc(){
    <!--
    //创建ajax对象。
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    var url='http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_send.asp';
    
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
      document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","./newfile.php",true);
    xmlhttp.send();
    }
    //-->
    </script>
    
    
    <style>
    <!--
    div{
    border:1 solid red;
    width:300px;
    height:300px;
    }
    //-->
    </style>
    <body>
    <div>
    这边我不要变。
    
    </div>
    <div id='myDiv'>
    刷新好吗?
    <button type="button" onclick="loadXMLDoc()">请求数据</button>  
    
    </div>
    
    </body>
    
    </html>

    ajaxs基本用法。

    url="www.baidu.com?t="+Math.random();
    //避免缓存误导。
    var xmlhttp.open("GET",url,true);
    xmlhttp.send();
     

    ajax 提交POST数据

    <html>
    <meta http-equiv="Content-Type" charset="UTF-8"/>
    <head>
        <script type="text/javascript">
            function loadXMLDoc()
            {
                var xmlhttp;
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                    }
                }
    
                xmlhttp.open("POST","./result.php",true);
                xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                xmlhttp.send("user=xie&password=123456");
            }
        </script>
    </head>
    <body>
    
    <h2>AJAX</h2>
    <button type="button" onclick="loadXMLDoc()">请求数据</button>
    <div id="myDiv"></div>
    
    </body>
    </html>
  • 相关阅读:
    一些业内有名的网站收集
    WCF重载
    FCKEditor fckconfig.js配置,添加字体和大小 附:中文字体乱码问题解决
    查询第几条到第几条的数据的SQL语句
    SPOJ 9939 Eliminate the Conflict
    UVA 10534 Wavio Sequence
    HDU 3474 Necklace
    POJ 2823 Sliding Window
    UVA 437 The Tower of Babylon
    UVA 825 Walking on the Safe Side
  • 原文地址:https://www.cnblogs.com/canbefree/p/3698757.html
Copyright © 2020-2023  润新知