Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
81 lines (75 sloc) 3.13 KB
<!DOCTYPE html>
<html>
<head>
<title>Ajax Test</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<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>
<p id="message">This is message will be updated</p>
<button id="get_button_s">Get Request Success</button>
<button id="get_button_f">Get Request Failure</button>
<br><br>
<button id="post_button_s">Post Request Success</button>
<button id="post_button_f">Post Request Failure</button>
<script type="text/javascript">
var msg = document.getElementById("message");
var getBtnS = document.getElementById('get_button_s');
var postBtnS = document.getElementById('post_button_s');
var getBtnF = document.getElementById('get_button_f');
var postBtnF = document.getElementById('post_button_f');
getBtnS.onclick = function(e) {
e.preventDefault();
msg.innerHTML = "getting...";
$.ajax({
url: "http://localhost:3000/ws/data.json",
type: "get",
success: function(data) {
msg.innerHTML = "get success: " + data;
},
error: function(jqXHR, text) {
msg.innerHTML = "get error: " + jqXHR.responseText;
}
});
};
getBtnF.onclick = function(e) {
e.preventDefault();
msg.innerHTML = "getting...";
$.ajax({
url: "http://localhost:3000/ws/data.json?error=error.json",
type: "get",
error: function(jqXHR, text) {
msg.innerHTML = "get error: " + jqXHR.responseText;
}
});
};
postBtnS.onclick = function(e) {
e.preventDefault();
msg.innerHTML = "posting...";
$.ajax({
url: "http://localhost:3000/ws/data.json",
data: "key=value",
type: "post",
success: function(data) {
msg.innerHTML = "post success: " + data;
},
error: function(jqXHR, text) {
msg.innerHTML = "post error: " + jqXHR.responseText;
}
});
};
postBtnF.onclick = function(e) {
e.preventDefault();
msg.innerHTML = "posting...";
$.ajax({
url: "http://localhost:3000/ws/data.json",
data: "error=error.json",
type: "post",
error: function(jqXHR, text) {
msg.innerHTML = "post error: " + jqXHR.responseText;
}
});
};
</script>
</body>
</html>