jquery Load Event (Callback/data) usage and considerations _jquery

Source: Internet
Author: User
If bound to a Window object, it is triggered after all content has been loaded, including windows, frames, objects, and images. If bound on an element, it is triggered when the contents of the element are loaded.

Attention: Binding the load's handler function before the element is fully loaded will trigger the load after he has finished loading. If you bind later, it will never be triggered. So do not bind the Load event in $ (document). Ready (), because jquery binds the Load event after all the DOM loads have been completed. Therefore, use the Load method as much as possible to write the Load method at the top of the page.

The full format for calling the Load method is: Load (URL, [data], [callback]),
which
URL: Refers to the address of the file to be imported.
data: Optional parameters; Because load can not only import static HTML files, but also import dynamic scripts, such as PHP files, so to import a dynamic file, we can put the parameters to pass here.
callback: optional parameter; is another function that is executed after the Load method is invoked and the server responds.

One: How to use Data
1. Load a php file, the PHP file does not contain the pass parameter $ ("#myID"). Load ("test.php");
The result of test.php run is imported in the element with ID #myid 2. Load a PHP file that contains a pass parameter
$ ("#myID"). Load ("test.php", {"name": "Adam"});
The imported PHP file contains a pass-through parameter, similar to: TEST.PHP?NAME=ADAM3. Load a PHP file that contains multiple pass parameters. Note: The parameters are separated by commas
$ ("#myID"). Load ("test.php", {"name": "Adam", "Site": "61dh.com"});
The imported PHP file contains a pass-through parameter, similar to: TEST.PHP?NAME=ADAM&SITE=61DH.COM4. Loads a PHP file that takes an array as the parameter to pass
$ ("#myID"). Load ("test.php", {' myinfo[] ', ["Adam", "61dh.com"]});
The imported PHP file contains an array pass parameter. Note: Using load, these parameters are passed as post, so you cannot use get for parameters in test.php.

II: How to use callback
For example, we can use the callback function when the load method gets the server response and slowly displays the loaded content. The code is as follows:
Copy Code code as follows:

$ ("#go"). Click (function () {
$ ("#myID"). Load ("welcome.php", {"lname": "Cai", "fname": "Adam", function () {
$ ("#myID"). FadeIn (' slow ');
);
});

Note:
After the URL Riga of the load, you can follow the selector.
For example:
Copy Code code as follows:

$ ("body"). Load ("test.html #a");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.