Controls loading elements from a new page using the jquery load () method

Source: Internet
Author: User

Recently, using the jquery load () method in the project to load the page, first simply say the load () method.

Load (Url,data,callback), this method receives three parameters, the first one is the loaded page address, the second is the parameter to be uploaded to the server, and the third is a callback function that executes after the page is loaded successfully. Of these three parameters, data and callback are optional according to the specific project requirements. Here's the problem: put an empty div container on the page to load the new page, and after loading, you need to control the hidden state of the elements in the new page, which needs to get the elements loaded into the page and then proceed to the next step. Loading the page after the review element, loaded page content directly in the div container, I was in the load (URL) method, directly get the element to hide, but loaded page elements are not hidden, it was very confusing, I thought I was not introduced through the IFRAME page, why can't hide it? Later on-line search, and colleagues consulted, finally found a solution, in the load (Url,callback) method with a callback function, inside the callback function to get the element and hidden. This is why, personally, it may be related to the JS execution sequence, after the execution of the load (URL), the following code continues to execute, will not wait until load () execution is complete. Later on the web, the load () method loads the page asynchronously, so the page element is only available in the callback of load (). So, this small problem cost two hours of time, or the foundation is not solid AH. From this extension, the load () method loading page can in some cases replace the previously used IFRAME loading page, and there is an opportunity to try it later.

Controls loading elements from a new page using the jquery load () method

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.