JQuery-AJAX Load () methodJQuery Load () method
The JQuery load () method is a simple but powerful AJAX method.
The load () method loads the data from the server and puts the returned data into the selected element.
Grammar:
$(selector). Load(URL,data,callback);
The required URL parameter specifies the URL that you want to load.
The optional data parameter specifies the collection of query string key/value pairs that are sent with the request.
The optional callback parameter is the function name that is executed after the load () method completes.
Here is the content of the sample file ("Demo_test.txt"):
<h2>jQuery AJAX is a great feature! </H2> <p id="p1"> This is some text of the paragraph. </P>
The following example loads the contents of the file "Demo_test.txt" into the specified <div> element:
Instance$("#div1"). Load("demo_test.txt");
Try it?
You can also add the JQuery selector to the URL parameter.
The following example loads the contents of the id= "P1" element in the "Demo_test.txt" file into the specified <div> element:
Instance$("#div1"). Load("demo_test.txt #p1");
Try it?
The optional callback parameter specifies the callback function to be allowed after the load () method completes. The callback function can set different parameters:
- responsetxt -Contains the contents of the result when the call succeeds
- statustxt -Contains the state of the call
- xhr -Contains XMLHttpRequest objects
The following example displays a prompt box after the load () method finishes. If the load () method is successful, the "External content loading succeeded!" is displayed. , and if it fails, an error message is displayed:
Instance$("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); }); });
Try it?
Related Tutorials vb.net tutorial SQL statements Daquan ASP. NET Tutorial dreamweaver tutorial JavaScript Tutorial Flash tutorial VB Tutorial computer Two-level VFP access tutorial htm L Tutorial C # Tutorial Database tutorial I want to self-study web page design training software development I want to teach self-study network SQL Server 2008
JavaScript tutorial Jquery-ajax Load () method