码迷,mamicode.com
首页 > Web开发 > 详细

ajax 案例demo

时间:2014-12-19 17:23:41      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

<!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 + "\n "+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‘));

 

ajax 案例demo

标签:

原文地址:http://www.cnblogs.com/suihui/p/4174290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!