zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    导出大智慧L2要密码的公式
    SQL Server 索引结构及其使用
    职业式证券交易全貌向职业交易员进军者鉴[转]
    sqlite多字段拼接方法
    推荐两个UI、PSD文件搜索网站
    利用事件冒泡和阻止事件冒泡的例子
    js通过八个点 拖动改变div大小
    匿名函数运用js脚本一对圆括号
    js对象转换为json格式的jquery辅助类
    简单清晰的缓冲运动框架
  • 原文地址:https://www.cnblogs.com/canbefree/p/3698757.html
Copyright © 2011-2022 走看看