zoukankan      html  css  js  c++  java
  • ajax随用随看

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>ajax案例</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript">
    function test(){
    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){
    //alert(xmlhttp.responseText);
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    }
    // xmlhttp.open("GET","/ajax/test.txt",true);
    xmlhttp.open("GET","ajax.php?id=10",true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>

    <div id="myDiv"><h2>这里的内容会变化哦~~~</h2></div>
    <button type="button" onclick="test()">click</button>

    </body>
    </html>

    ajax.php

    <?php
    $id=$_GET['id'];
    if($id==1)
    {
    echo "11111111111";
    }
    else
    {
    echo "22222222222";
    }

  • 相关阅读:
    css+js实现的一个导航栏
    各类插件的网页库
    vue构建项目全过程
    手把手教你使用Git
    创建git库
    VUE.JS的安装
    reset.css 初始化
    分布式事务方案
    线程池的参数
    每秒上千订单场景下,如何对分布式锁的并发能力进行优化
  • 原文地址:https://www.cnblogs.com/S-Ping/p/4231493.html
Copyright © 2011-2022 走看看