Sometimes we need to make AJAX call in our Web page. The purpose of AJAX call is that you want to get/submit data without refreshing your page or you want to submit your form by calling an API. We can do this very easily by using ajax() method of jQuery.
Example: In the below code I'm making an AJAX call to login a user
//Ajax login user at launch
function ajaxLoginWebUser()
{
$.ajax({
url: 'loginWebUser', //Here you will pass the API url you want to call
type : 'get',
async : true,
cache: false,
data : {
userEmail : userEmail
},
beforeSubmit: function() { },
success: function(response) {
if(response.status == 'OK')
{
alert("success...";
}
else
{
alert("FAILED, Try again ... "+response.message);
}
},
error : function() { alert("FAILED, Try again ... " + "System error occured, please try again ...");}
});
}
Hope this will help you :)
0 Comment(s)