JavaScript-The second time the AJAX fetch page, Main.js did not reload, or that all JS did not reload the problem

Source: Internet
Author: User



When using AJAX to do the drawer effect, when the second Ajax extract page, JS did not reload, how to solve the problem?

Reply content:



When using AJAX to do the drawer effect, when the second Ajax extract page, JS did not reload, how to solve the problem?

My blog used a similar pjax technique, and the design encountered a similar problem.

In fact, the root cause is not JS does not reload, in fact, he does not need to reload, because it has been loaded.
The root cause is that it will not be re-executed.

You can define a file called bootstrap.js .
And then re-execute one at a time to re-load the JS can be.
PS If you have previously written code in a common area, that is not part of any function, you need to encapsulate it yourself into a function and execute it here.
Like what:
A.js

console.log('test');

This JS is actually loaded, also executed, under normal circumstances will not be executed again.
Then you need to modify it to
A.js

var initAJs=function(){    console.log('test');}

Then execute the Pjax when it returns successfully.
initAjsCan.

  • 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.