UNPKG

2.01 kBHTMLView Raw
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>Test: Ajax</title>
7 <link href="../example/lib/weui.min.css" rel="stylesheet"/>
8 <link href="../example/lib/demo.css" rel="stylesheet"/>
9
10 <script src="../example/lib/zepto.min.js"></script>
11 <script src="../example/lib/zepto.touch.min.js"></script>
12
13 <script src="../dist/vconsole.min.js"></script>
14
15</head>
16<body ontouchstart>
17 <div class="page">
18 <a onclick="asyncAjax()" href="javascript:;" class="weui_btn weui_btn_default">asyncAjax</a>
19 <a onclick="syncAjax()" href="javascript:;" class="weui_btn weui_btn_default">syncAjax</a>
20 <a onclick="postAjax()" href="javascript:;" class="weui_btn weui_btn_default">postAjax</a>
21 </div>
22</body>
23</html>
24
25<script>
26
27function postAjax() {
28 console.info('postAjax() Start');
29 $.ajax({
30 type: 'POST',
31 url: 'success.json',
32 data: {
33 id: Math.random()
34 },
35 dataType: 'json',
36 success: function(data) {
37 console.log('postAjax Response:', data);
38 },
39 error: function(xhr, type) {
40 console.log('postAjax Error:', type);
41 }
42 });
43 console.info('postAjax() End');
44}
45
46function asyncAjax() {
47 console.info('asyncAjax() Start, response should be logged after End');
48 $.ajax({
49 type: 'GET',
50 url: 'success.json',
51 async: true,
52 dataType: 'json',
53 success: function(data) {
54 console.log('asyncAjax Response:', data);
55 },
56 error: function(xhr, type) {
57 console.log('asyncAjax Error:', type);
58 }
59 });
60 console.info('asyncAjax() End');
61}
62
63function syncAjax() {
64 console.info('syncAjax() Start, response should be logged before End');
65 $.ajax({
66 type: 'GET',
67 url: 'success.json',
68 async: false,
69 dataType: 'json',
70 success: function(data) {
71 console.log('syncAjax Response:', data);
72 },
73 error: function(xhr, type) {
74 console.log('syncAjax Error:', type);
75 }
76 });
77 console.info('syncAjax() End');
78}
79
80</script>
\No newline at end of file