Ajax :
It is s process of getting or reteriving the content without refreshing the whole page.
We can do this using javascript and JQuery.
There are different method for ajax call in javascript and jquery.
Javascript :
<script>
function loadingData() {
var xmlhttp;
var urldata = 'http://demo.com/key/value/one/two';
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
else if(xmlhttp.status == 400) {
alert('There was an error 400')
}
else {
alert('something else other than 200 was returned')
}
}
}
xmlhttp.open("GET", urldata, true);
xmlhttp.send();
}
loadingData();
</script>
JQuery :
$.ajax({
type: "GET",
url: "/myapp/demo.html",
data: {'id': postId.val()},
dataType: "json",
success: function(response){
alert("success");
},
error: function(response){
alert("Error:" + response);
}
});
0 Comment(s)