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
views:
33answers:
2I 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.