<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Examples</title> <meta name="description" content=""> <meta name="keywords" content=""> <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.min.css"> <script src="./bootstrap/js/jquery.min.js"></script> <script src="./bootstrap/js/bootstrap.min.js"></script> </head> <style type="text/css"> .header{height: 30px;background:#565657;} </style> <body> <div class="header"> <div class="contianer-fluid"> <div class="row"> <div id="id">33333</div> </div> </div> </div> </body> </html>
<script type="text/javascript"> // $("#id").click(function(){ // ajax_send(); // }) function ajax_send(func){ var query = new Object(); query.id = $("#id").val(); $.ajax({ type:"POST", data:query, url:"test.php", datatype:"json", success:function(res){ var res=JSON.parse(res); func.call(this,res); } }); } //一种自动调用ajax的方法 (function(){ ajax_send(function(res){ if(res.status==1){ console.log(res); // alert("回调成功"); }; }); })(); </script>
php后台
<?php header("Content-type: text/html; charset=utf-8"); $arr=array(‘tel‘=>18350033658,‘name‘=>"天涯alone" ,"学生"=>array(‘no‘=>33,‘score‘=>‘95‘)); $arr[‘status‘]=1; echo(json_encode($arr));
时间: 2024-11-08 19:23:34