zoukankan      html  css  js  c++  java
  • 一个ajax实例

    一个ajax实例

     
    html
     
    1. <!DOCTYPE html>
    2. <html lang="zh-cn">
    3. <head>
    4. <meta charset="utf-8">
    5. <meta name="renderer" content="webkit">
    6. <!--360,以webkit内核进行渲染-->
    7. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    8. <!--以最新内核进行渲染。-->
    9. <meta http-equiv="Cache-Control" content="no-siteapp"/>
    10. <!--百度禁止转码-->
    11. <title>moyu demo</title>
    12. <meta name="keywords" content="demo 测试 魔芋">
    13. <meta name="description" content="魔芋的测试示例">
    14. <meta name="robots" content="index,follow">
    15. <!--定义网页搜索引擎索引方式-->
    16. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    17. <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
    18. <style>
    19. </style>
    20. </head>
    21. <body>
    22. <script>
    23. function showUser(str){
    24. if(str ==""){
    25. document.getElementById("txtHint").innerHTML ="";
    26. return;
    27. }
    28. if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    29. xmlhttp =newXMLHttpRequest();
    30. }else{// code for IE6, IE5
    31. xmlhttp =newActiveXObject("Microsoft.XMLHTTP");
    32. }
    33. xmlhttp.onreadystatechange =function(){
    34. if(xmlhttp.readyState ==4&& xmlhttp.status ==200){
    35. document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
    36. }
    37. }
    38. xmlhttp.open("GET","http://localhost/moyu.php?q="+ str,true);
    39. xmlhttp.send();
    40. }
    41. </script>
    42. </head>
    43. <body>
    44. <form>
    45. <select name="users" onchange="showUser(this.value)">
    46. <option value="">Select a person:</option>
    47. <option value="1">PeterGriffin</option>
    48. <option value="2">LoisGriffin</option>
    49. <option value="3">GlennQuagmire</option>
    50. <option value="4">JosephSwanson</option>
    51. </select>
    52. </form>
    53. <br>
    54. <div id="txtHint"><b>Person info will be listed here.</b></div>
    55. </body>
    56. </html>
     
     
    php
     
     
    1. <?php
    2. $q=$_GET["q"];
    3. echo "$q";
    4. ?>
     
     
     
    魔芋测试:
    4.gif
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     



  • 相关阅读:
    设计模式-适配器模式(09)
    windows电脑使用技巧及常用CMD
    接口调用方法
    矩阵对角线和
    函数基础小结
    文件处理实战之购物车系统
    文件处理小结
    Python进阶实战之三级菜单
    Python进阶小结
    Python深浅拷贝
  • 原文地址:https://www.cnblogs.com/moyuling/p/5272506.html
Copyright © 2011-2022 走看看