Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make AJAX call in jQuery?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 342
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: