Skip to content
Newer
Older
100644 81 lines (75 sloc) 3.13 KB
67c9f1a @marty-wang add structure for web service
authored Nov 2, 2011
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Ajax Test</title>
de6f7a4 @marty-wang re-org samples
authored Nov 3, 2011
5 <script type="text/javascript" src="js/jquery.min.js"></script>
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
6 </head>
7 <body>
fee2128 @marty-wang add loading message in ajax.html
authored Nov 5, 2011
8 <p>Open this page locally or run through other web server. You will see that the cross-domain ajax calls will work. This will be very handy for local development, because you will not need to change anything in your code, and it will just work as if they were same-domain ajax calls. Also you have the ability to specify the webservice delay so that you can test your loader.</p>
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
9
10 <p id="message">This is message will be updated</p>
3c5dc46 @marty-wang add webserive for post and get
authored Nov 3, 2011
11 <button id="get_button_s">Get Request Success</button>
12 <button id="get_button_f">Get Request Failure</button>
13 <br><br>
14 <button id="post_button_s">Post Request Success</button>
15 <button id="post_button_f">Post Request Failure</button>
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
16 <script type="text/javascript">
17 var msg = document.getElementById("message");
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
18 var getBtnS = document.getElementById('get_button_s');
19 var postBtnS = document.getElementById('post_button_s');
20 var getBtnF = document.getElementById('get_button_f');
21 var postBtnF = document.getElementById('post_button_f');
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
22
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
23 getBtnS.onclick = function(e) {
fee2128 @marty-wang add loading message in ajax.html
authored Nov 5, 2011
24 e.preventDefault();
25 msg.innerHTML = "getting...";
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
26 $.ajax({
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
27 url: "http://localhost:3000/ws/data.json",
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
28 type: "get",
29 success: function(data) {
30 msg.innerHTML = "get success: " + data;
9f58f51 @marty-wang complete mock webservice support
authored Nov 4, 2011
31 },
32 error: function(jqXHR, text) {
33 msg.innerHTML = "get error: " + jqXHR.responseText;
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
34 }
35 });
36 };
37
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
38 getBtnF.onclick = function(e) {
39 e.preventDefault();
fee2128 @marty-wang add loading message in ajax.html
authored Nov 5, 2011
40 msg.innerHTML = "getting...";
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
41 $.ajax({
9f58f51 @marty-wang complete mock webservice support
authored Nov 4, 2011
42 url: "http://localhost:3000/ws/data.json?error=error.json",
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
43 type: "get",
44 error: function(jqXHR, text) {
45 msg.innerHTML = "get error: " + jqXHR.responseText;
46 }
47 });
48 };
49
50 postBtnS.onclick = function(e) {
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
51 e.preventDefault();
fee2128 @marty-wang add loading message in ajax.html
authored Nov 5, 2011
52 msg.innerHTML = "posting...";
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
53 $.ajax({
9f58f51 @marty-wang complete mock webservice support
authored Nov 4, 2011
54 url: "http://localhost:3000/ws/data.json",
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
55 data: "key=value",
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
56 type: "post",
57 success: function(data) {
58 msg.innerHTML = "post success: " + data;
9f58f51 @marty-wang complete mock webservice support
authored Nov 4, 2011
59 },
60 error: function(jqXHR, text) {
61 msg.innerHTML = "post error: " + jqXHR.responseText;
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
62 }
63 });
64 };
65
66 postBtnF.onclick = function(e) {
fee2128 @marty-wang add loading message in ajax.html
authored Nov 5, 2011
67 e.preventDefault();
68 msg.innerHTML = "posting...";
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
69 $.ajax({
9f58f51 @marty-wang complete mock webservice support
authored Nov 4, 2011
70 url: "http://localhost:3000/ws/data.json",
71 data: "error=error.json",
3c5dc46 @marty-wang add webserive for post and get
authored Nov 4, 2011
72 type: "post",
73 error: function(jqXHR, text) {
74 msg.innerHTML = "post error: " + jqXHR.responseText;
67c9f1a @marty-wang add structure for web service
authored Nov 3, 2011
75 }
76 });
77 };
78
79 </script>
80 </body>
81 </html>
Something went wrong with that request. Please try again.