Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Ajax call using Javascript and JQuery

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 333
    Comment on it

    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)

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: