首页 > Web开发 > 详细

jquery的get方式发送AJAX请求

时间:2019-01-07 01:13:00      阅读:193      评论:0      收藏:0      [点我收藏+]
技术分享图片
 1 <!DOCTYPE html>
 2 <html>
 3   <head>
 4     <meta http-equiv="content-type" content=‘text/html;charset=utf-8‘>
 5     <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" ></script>
 6     <title></title>
 7   </head>
 8   <body>
 9     <script>
10       //* get方式向php传递参数name和age 2种方法
11       //* data为php返回值 可指定格式
12       /*
13         url:待载入页面的URL地址
14         data:待发送 Key/value 参数。
15         callback:载入成功时回调函数。
16         type:返回内容格式,xml, html, script, json, text, _default。
17        */
18       $.get(./jquery_get.php?age=11,{name:Harry},function(data){
19         $(#h1).append(<h2>+ data.msg +</h2>);
20       },json);
21     </script>
22     <h1 id=‘h1‘></h1>
23   </body>
24 </html>
jquery_get.html
技术分享图片
 1 <?php
 2   //接受参数
 3   $name=$_GET[‘name‘];
 4   $age=$_GET[‘age‘];
 5   if ($name==‘Harry‘ && $age==12) {
 6     echo json_encode(
 7       array(
 8         ‘os‘=>‘windows‘,
 9         ‘code‘=>‘php‘
10       )
11     );
12   }else {
13     echo json_encode(array(
14         ‘code‘=>404,
15         ‘msg‘=>‘not found‘
16       )
17     );
18   }
19  ?>
jquery_get.php

 

jquery的get方式发送AJAX请求

原文:https://www.cnblogs.com/t-young1201/p/10231047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!