zoukankan      html  css  js  c++  java
  • ajax 案例demo

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
        <head>
            <title>新建网页</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <meta name="description" content="" />
            <meta name="keywords" content="" />
    
            <script type="text/javascript" src="jquery-2.1.3.min.js"></script>
    
            <script type="text/javascript">
            function f1(){
                //$.ajax(json参数)
                $.ajax({
                    url:'16.php',
                    data:{addr:'北京','people':'2000',area:'10万',on:'123'},
                    dataType:'json',
                    type:'post',
                    success:function(msg){
                        //msg接收服务器端返回的数据
                       dump_obj(msg);
                        //alert(msg.name+'--'+msg.age);
                    }
                });
            }
            </script>
    
    
            <script type="text/javascript">
                function dump_obj(myObject) {  
                      var s = "";  
                      for (var property in myObject) {  
                       s = s + "
     "+property +": " + myObject[property] ;  
                      }  
                      alert(s);  
                }  
    
            </script>
    
            <style type="text/css">
         
            </style>
        </head>
    
        <body>
            <h2>ajax调用</h2>
    
            <input type="button" value="触发" onclick="f1()" />
        </body>
    </html>
    <?php
    
    echo json_encode($_POST);
    
    //echo json_encode(array('name'=>'linken','age'=>'20'));
  • 相关阅读:
    Day4 0708
    Day2 0706
    两道递推公式题的解题报告
    博客还需优化
    飞行路线Luogu4568
    堆优化Dijkstra(Luogu 4779)
    2019四等奖的清明节征文
    2019四等奖的叶圣陶初稿
    Luogu P1072 Hankson的趣味题
    Loj10022 埃及分数(迭代加深搜索IDDFS)
  • 原文地址:https://www.cnblogs.com/suihui/p/4174290.html
Copyright © 2011-2022 走看看