In this tutorial we will discuss ajax tutorial with example
AJAX is a system for send and receive record from server without reloading the page.
AJAX stands for Asynchronous JavaScript And XML.
You can update any part of website page using AJAX.
It is not a just programming language.
The main purpose of using AJAX to website is to avoid page refresh and do multiple work on a same web page.
Example: add, Update, remove , fetch data in one page.
How it works:
- User sends request from the web page and a javascript call goes to XMLHttpRequest object.
- .HTTP Request will sent to the server by XMLHttpRequest object.
- Server get the data from the database using JSP, PHP, Servlet, ASP.net etc file.
- Data is fetching and view the record in web page using HTML.
History
In 2005 by Google, used AJAX for show suggestions to user.
<script>
$(document).ready(function() {
$('#butsave').on('click', function() {
$("#butsave").attr("disabled", "disabled");
var name = $('#name').val();
var email = $('#email').val();
$.ajax({
url: "save.php",
type: "POST",
data: {
name: name,
email: email
},
cache: false,
success: function(dataResult){
var dataResult = JSON.parse(dataResult);
if(dataResult.statusCode==200){
$('#success').html('Data added successfully !');
}
else if(dataResult.statusCode==201){
alert("Error occured !");
}
}
});
});
});
</script>
Also Read
0 Comments