简体   繁体   中英

is there a way to make the browser reload my javascript code after an ajax call

how can i make the browser re-evaluate all my javascript after i make an ajax call. i am using mootools framework and i would like to reload the javascript added at the header portion of my html page

I am assuming that your ajax call is returning javascript as part of the response. I am not too familiar with mootools, but most of the popular frameworks allow you to eval javascript from a string. So, you can just grab the appropriate return value from the ajax call and "eval" it.

If that is not what you are trying to do, then I do not know what problem you are trying to solve.

After adding a new script tag using Javascript, the code within the newly loaded script is automatically evaluated. You cannot force the browser to re-evaluate the all the Javascript.

A possible solution to this is to place all your code in a function and then call that function when you get ajax response:

function myCode()  {
  // Your code here
}

myCode();
// Also call myCode when you get the Ajax reply

I am not familiar with motools so this is a general Javascript example. Also, on a side note, you generally shouldn't need to do this. Perhaps you should think about a better code design.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM