• 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>
  • 相关阅读:
    ES的基本用法
    Elasticsearch安装部署
    jquery-layer弹框在火狐浏览器中弹框不显示的问题
    MySQL中横表和竖表相互转换
    echarts--迁徙图特性简介
    Lucene入门案例一
    Lucene入门简介
    SpringMVC中的拦截器
    SpringMVC中Json数据格式转换
    SpringMVC中的文件上传
  • 原文地址:https://www.cnblogs.com/canbefree/p/3698757.html
Copyright © 2020-2023  润新知