Page 1 of 1
Jquery: destroy ajax loaded scripts
Posted: Sun Mar 14, 2010 11:44 am
by Ragnis
I have an AJAX based site.
Then i load a page, which contains some scripts.
Now i empty the content container using .empty(); and load another page.
But .empty(); won't remove those scripts, which came with the first page.
And when i load again the first page, the script, which came with it, will be executed twice.
Re: Jquery: destroy ajax loaded scripts
Posted: Sun Mar 14, 2010 11:56 am
by kaszu
Use iframe or check in <SCRIPT> that they are not already executed.
Re: Jquery: destroy ajax loaded scripts
Posted: Sun Mar 14, 2010 12:43 pm
by Ragnis
When i load the page, i need to execute the script, but only once.
And when i load the page again, i want again to execute it only once.
But it will execute the script as many times as i have loaded this page.
Re: Jquery: destroy ajax loaded scripts
Posted: Sun Mar 14, 2010 4:37 pm
by kaszu
And when i load the page again, i want again to execute it only once.
Isn't that what's happening right now? Each time you load a page using ajax all scripts in it are executed!
check in <SCRIPT> that they are not already executed
There's no other easy answer as I know.
Re: Jquery: destroy ajax loaded scripts
Posted: Mon Mar 15, 2010 10:33 am
by Ragnis
But i want the script to be removed when i load another page.
Re: Jquery: destroy ajax loaded scripts
Posted: Mon Mar 15, 2010 10:46 am
by pickle
Can you modify the script in the included page? If so, have it only execute if some magic variable, say "loadedScriptRun" == 0. Once you load the page the first time, set that variable to 1, then on subsequent loads, "loadedScriptRun" will != 0, and won't run.
Re: Jquery: destroy ajax loaded scripts
Posted: Mon Mar 15, 2010 11:12 am
by Ragnis
If i won't get any better soultion, then i think i'll use that variable thing.
But how others do theese ajax sites?
Re: Jquery: destroy ajax loaded scripts
Posted: Mon Mar 15, 2010 2:23 pm
by pickle
I don't load code multiple times that I only want run once.