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.
Jquery: destroy ajax loaded scripts
Moderator: General Moderators
Re: Jquery: destroy ajax loaded scripts
Use iframe or check in <SCRIPT> that they are not already executed.
- Ragnis
- Forum Commoner
- Posts: 31
- Joined: Thu Nov 13, 2008 12:35 pm
- Location: Saaremaa, Estonia, Europe, Asia, Planet Earth, The Solar System, Milky way.
Re: Jquery: destroy ajax loaded scripts
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.
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
Isn't that what's happening right now? Each time you load a page using ajax all scripts in it are executed!And when i load the page again, i want again to execute it only once.
There's no other easy answer as I know.check in <SCRIPT> that they are not already executed
- Ragnis
- Forum Commoner
- Posts: 31
- Joined: Thu Nov 13, 2008 12:35 pm
- Location: Saaremaa, Estonia, Europe, Asia, Planet Earth, The Solar System, Milky way.
Re: Jquery: destroy ajax loaded scripts
But i want the script to be removed when i load another page.
Re: Jquery: destroy ajax loaded scripts
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- Ragnis
- Forum Commoner
- Posts: 31
- Joined: Thu Nov 13, 2008 12:35 pm
- Location: Saaremaa, Estonia, Europe, Asia, Planet Earth, The Solar System, Milky way.
Re: Jquery: destroy ajax loaded scripts
If i won't get any better soultion, then i think i'll use that variable thing.
But how others do theese ajax sites?
But how others do theese ajax sites?
Re: Jquery: destroy ajax loaded scripts
I don't load code multiple times that I only want run once.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.