Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 48 lines (44 sloc) 1.755 kb
67c9f1a @marty-wang add structure for web service
authored
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Ajax Test</title>
5 <script type="text/javascript" src="jquery.min.js"></script>
6 </head>
7 <body>
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.</p>
9
10 <p id="message">This is message will be updated</p>
11 <button id="get_button">Get Request</button>
12 <button id="post_button">Post Request</button>
13 <script type="text/javascript">
14 var msg = document.getElementById("message");
15 var getBtn = document.getElementById('get_button');
16 var postBtn = document.getElementById('post_button');
17
18 getBtn.onclick = function(e) {
19 e.preventDefault();
20 $.ajax({
21 url: "http://localhost:3000/ws/requested_file",
22 type: "get",
23 success: function(data) {
24 msg.innerHTML = "get success: " + data;
25 },
26 error: function(err) {
27 msg.innerHTML = "error: " + err;
28 }
29 });
30 };
31
32 postBtn.onclick = function(e) {
33 e.preventDefault();
34 $.ajax({
35 url: "http://localhost:3000/ws",
36 type: "post",
37 success: function(data) {
38 msg.innerHTML = "post success: " + data;
39 },
40 error: function(err) {
41 msg.innerHTML = "error: " + err;
42 }
43 });
44 };
45
46 </script>
47 </body>
48 </html>
Something went wrong with that request. Please try again.