If it is bound to a window object, it is triggered after all content is loaded, including the window, frame, object, and image. If it is bound to an element, it is triggered after the content of the element is loaded.
Note:: The load handler is triggered only after the element is fully loaded. If it is bound later, it will never be triggered. Therefore, do not bind the load event in $ (document). ready (), because jQuery will bind the load event after all DOM loads are completed. Therefore, when using the load method, try to write the load method at the top of the page.
The complete format for calling the load method is: load (url, [data], [callback]),
Where:
• Url: the address of the file to be imported.
• Data: an optional parameter. Because Load can not only import static html files, but also dynamic scripts, such as PHP files, when importing dynamic files, we can put the parameters to be passed here.
• Callback: an optional parameter. It is another function that is executed after the load method is called and the server response is obtained.
I. How to use data
1. load a php file without passing the parameter $ ("# myID"). load ("test. php ");
// Import the result of test. php running in the element whose id is # myID 2. Load a php file, which contains a passing Parameter
$ ("# MyID"). load ("test. php", {"name": "Adam "});
// The imported php file contains a passing parameter, similar to: test. php? Name = Adam3. load a PHP file containing multiple passing parameters. Note: parameters are separated by commas (,).
$ ("# MyID"). load ("test. php", {"name": "Adam", "site": "61dh.com "});
// The imported php file contains a passing parameter, similar to: test. php? Name = Adam & site = 61dh. com4. load a PHP file. The php file uses an array as the passing parameter.
$ ("# MyID"). load ("test. php", {'myinfo [] ', ["Adam", "61dh.com"]});
// The imported PHP file contains an array for passing parameters. Note: using load, these parameters are passed in POST mode. Therefore, GET parameters cannot be obtained in test. php.
Ii. How to Use callback
For example, you can use the callback function to slowly display the loaded content after the load method obtains the server response. The Code is as follows:Copy codeThe Code is as follows: $ ("# go"). click (function (){
$ ("# MyID"). load ("welcome. php", {"lname": "Cai", "fname": "Adam", function (){
$ ("# MyID"). fadeIn ('low ');}
);
});
Note:
Add a space in the load url and you will be able to follow the selector.
For example:Copy codeThe Code is as follows: $ ("body"). load ("test.html # ");