Jquery Load

jQuery - AJAX load() Method


jQuery load() Method

The jQuery load() method is a simple, simply powerful AJAX method.
The load() method loads information from a server together with puts the returned information into the selected element.
Syntax:
$(selector).load(URL,data,callback);
The required URL parameter specifies the URL you lot wishing to load.
The optional information parameter specifies a laid of querystring key/value pairs to mail along amongst the request.
The optional callback parameter is the cite of a component to hold upward executed subsequently the load() method is completed.
Here is the content of our instance file: "demo_test.txt":
<h2>jQuery together with AJAX is FUN!!!</h2>
<p id="p1">This is or together with thus text inwards a paragraph.</p>
The next instance loads the content of the file "demo_test.txt" into a specific <div> element:

Example

$("#div1").load("demo_test.txt");
It is likewise possible to add together a jQuery selector to the URL parameter.
The next instance loads the content of the chemical constituent amongst id="p1", within the file "demo_test.txt", into a specific <div> element:

Example

$("#div1").load("demo_test.txt #p1");
The optional callback parameter specifies a callback component to run when the load() method is completed. The callback component tin convey unlike parameters:
  • responseTxt - contains the resulting content if the telephone band succeeds
  • statusTxt - contains the condition of the call
  • xhr - contains the XMLHttpRequest object
The next instance displays an warning box subsequently the load() method completes. If the load() method has succeeded, it displays "External content loaded successfully!", together with if it fails it displays an fault message:

Example

$("button").click(function(){
    $("#div1").load("demo_test.txt", function(responseTxt, statusTxt, xhr){
        if(statusTxt == "success")
            alert("External content loaded successfully!");
        if(statusTxt == "error")
            alert("Error: " + xhr.status + ": " + xhr.statusText);
    });
});


Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?