Javascript-Ajax asynchronous loading, event triggering problems

Source: Internet
Author: User
Ajax asynchronously loads some pages (target-page). a button exists in the target-page, and you want to set an onclick function for the button. However, the trigger logic is always unavailable: front-end jqueryload () (ajax asynchronous) load the page, btn put the pseudo code in the target-page... ajax asynchronously loads some pages (target-page). a button exists in the target-page and you want to set an onclick function for the button. Unable to trigger

Logic: front-end jqueryload()(Ajax asynchronous) load pages, btn placed in target-page

The pseudocode is as follows: (if the code is too long, it will be replaced with the pseudo code)

Ajax. js:

$ (Function () {$ (xxx ). load (target-page); function a () {codes} setTimeout (function () {$ (btn ). click (a); // use settimeout to solve}, 0 );});

Can someone help me explain the principles and correct solutions ??

I personally think that the problem is that it is triggered after the basic js content (variable/function declaration) is loaded asynchronously, and the elements cannot be obtained.

Reply content:

Ajax asynchronously loads some pages (target-page). a button exists in the target-page and you want to set an onclick function for the button.Unable to trigger

Logic: front-end jqueryload()(Ajax asynchronous) load pages, btn placed in target-page

The pseudocode is as follows: (if the code is too long, it will be replaced with the pseudo code)

Ajax. js:

$ (Function () {$ (xxx ). load (target-page); function a () {codes} setTimeout (function () {$ (btn ). click (a); // use settimeout to solve}, 0 );});

Can someone help me explain the principles and correct solutions ??

I personally think that the problem is that it is triggered after the basic js content (variable/function declaration) is loaded asynchronously, and the elements cannot be obtained.

Take a look at the document: http://api.jquery.com/load/

In addition,target-pageIt's not a variable. what is it?

Reference Code

// The second parameter is data. null is not directly given, or {} // you can omit the example in the document and use callback as the second parameter $ (xxx ). load (url, function () {// do callback here });

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.