zoukankan      html  css  js  c++  java
  • AJAX 简单例程示例

    • index.html

        <html>
        <head>    
        <script>
        function showHint(str)
        {
            if (str.length==0)
            {
                return;
            }
            if (window.XMLHttpRequest)
            {
                xmlhttp=new XMLHttpRequest();   // 申请一个  XMLHttpRequest 的 对象
            }
            else
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                    console.log(xmlhttp.responseText);
                }
            }
            xmlhttp.open("GET","gethint.php?q="+str,true);    // 打开,并传递一个数据过去,通过 GET 的方式
            xmlhttp.send();        // 发送
        }
        </script>
    
        <button onclick="showHint('date')"> test it </button>
    
        </head>
        <body>
        </body>
        </html>
    
    • gethint.php

          1 <?php
          2
          3 $q=$_GET["q"];   // 这里获取到上面的数据
          4
          5 echo $q;
          6 ?>
    
  • 相关阅读:
    js函数调用模式
    js闭包和回调
    js原型
    oracle sql优化笔记
    shell脚本学习
    程序与资源管理
    vi/vim学习
    压缩和解压缩
    用户及用户组
    万用字符和特殊字符
  • 原文地址:https://www.cnblogs.com/chenfulin5/p/9052710.html
Copyright © 2011-2022 走看看