Jquery: destroy ajax loaded scripts

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
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.

Jquery: destroy ajax loaded scripts

Post 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.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Jquery: destroy ajax loaded scripts

Post by kaszu »

Use iframe or check in <SCRIPT> that they are not already executed.
User avatar
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

Post 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.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Jquery: destroy ajax loaded scripts

Post 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.
User avatar
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

Post by Ragnis »

But i want the script to be removed when i load another page.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Jquery: destroy ajax loaded scripts

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
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

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Jquery: destroy ajax loaded scripts

Post by pickle »

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.
Post Reply