Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Loading simple data with the help of ajax

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 230
    Comment on it

     

    If we want some part of our website to load but we dont want other part to be loaded for this purpose ajax is used . Ajax stands for Asynchronous JavaScript and XML it helps us to load particular part of the page but not the whole page. AJAX load data from the background  and show it on the page, without reloading the entire page.

    Loading simple data

    We can simply load any data with help of ajax. JQuery gives us load() method by which we can acquire it.

     syntax:-

    below is the syntax of load method.

    [selector].load( URL, [data], [callback] );

    URL :- it contains the url we want to load.

    data :- This is a optional parameter which contains data in the form of key/value pairs which we want to send with the request.

    callback:-  This is also a optional parameter this specify the name of the function which we want to call ,when load() method get completed. 

    Below is the simple code for explaining load()method.

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#text-change").load("ajax_load.txt");
        });
    });
    </script>
    </head>
    <body>
    
    <div id="text-change"><h2>U will see new text after clicking on below button</h2></div>
    
    <button>Click me</button>
    
    </body>
    </html>
    

     

 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: