Home > Article > Backend Development > javascript - When ajax extracts the page for the second time, main.js is not reloaded, or in other words, all js are not reloaded.
Rendering:
When using Ajax to create the drawer effect, when ajax extracts the page for the second time, the js is not reloaded. How to solve this problem?
Rendering:
When using Ajax to create the drawer effect, when ajax extracts the page for the second time, the js is not reloaded. How to solve this problem?
My blog uses similar pjax
technology, and I encountered similar problems in the original design.
In fact, the fundamental reason is not that js is not reloaded. In fact, it does not need to be reloaded at all because it has already been loaded.
The fundamental reason is that it will not be re-executed.
You can define a file called bootstrap.js
.
Then re-execute the js that need to be reloaded one by one.
ps If you have code written in the public area before, that is, it does not belong to any function, you need to encapsulate it into a function yourself and then execute it here.
For example:
a.js
<code>console.log('test');</code>
This js has actually been loaded and executed. Under normal circumstances, it will not be executed again.
Then you need to modify it to
a.js
<code>var initAJs=function(){ console.log('test'); }</code>
Then execute initAjs
when pjax returns successfully.