首页 > Web开发 > 详细

jquery的ajax方式发送AJAX请求

时间:2019-01-07 10:12:38      阅读:154      评论: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     <button type="button" id="bid">test</button>
10     <script>
11       $(#bid).click(function(event) {
12         $.ajax({
13           url:./jquery_ajax.php,
14           dataType:json,
15           type:GET,
16           timeout:2000,  //毫秒
17           success:function(data,status){
18             //* data 可能是 xmlDoc, jsonObj, html, text, 等等...
19           },
20           error:function(XMLHttpRequest, textStatus, errorThrown){
21             //* 通常 textStatus 和 errorThrown 之中,只有一个会包含信息
22             if (textStatus === timeout) {
23               alert(请求超时!);
24               setTimeout(function(){
25                 alert(准备重新请求!);
26               },2000);
27             }
28           }
29         });
30       });
31 
32     </script>
33   </body>
34 </html>
jquery_ajax.html
技术分享图片
1 <?php
2   sleep(3);
3   echo json_encode(array(‘name‘=>‘Harry‘));
4  ?>
jquery_ajax.php

jquery的ajax方式发送AJAX请求

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

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