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>