The load () method loads the data from the server and puts the returned data into the selected element.
The following example loads the contents of the id= "P1" element in the "Demo_test.txt" file into the specified <div> element:
$ ("#div1"). Load ("demo_test.txt #p1");
Reference URL: http://www.w3cschool.cc/jquery/jquery-ajax-load.html
The optional callback parameter specifies the callback function to be allowed when the load () method is completed. 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:
$("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); });});
jquery and server Exchange data--ajax (asynchronous JavaScript and XML)