snovelli
snovelli

Reputation: 6058

How to stop a JQuery.load'ed inner scripts

I'm developing a dynamic web page with nested pages. Inner pages have their own script to be live and modular.

The problem comes when i want to remove one of the inner pages. Infact the HTML code is removed but the inner script keeps running.

Is it possible to stop the script?

This is a brief view of my solution:

Note that in this sample the ID are all the same but in the real solution they are identified by unique ID using php GET["ID"] value.

outerPage.php

<HEAD>
    <script>
    var fRunUpdate = true;
        $(document).ready(function() {

           $("#inner1").load("inner.php");
           $("#inner2").load("inner.php");
           $("#inner3").load("inner.php");

        }
    </script>
</HEAD>
<BODY>
    <div id="inner1"></div>
    <div id="inner2"></div>
    <div id="inner3"></div>
</BODY>

innerPage.php

<HEAD>
    <script>
    var fRunUpdate = true;
        $(document).ready(function() {
           function update(){
               //do something
               $("#contentToUpdate").html("content");
               setTimeout(update,1000);
           }
        }
    </script>
</HEAD>
<BODY>
    <div id="contentToUpdate"></div>
</BODY>

Upvotes: 0

Views: 130

Answers (1)

Just code
Just code

Reputation: 13801

You will have to use stoptimeout or clear interval I just read out this link and get it

How to stop a setTimeout loop?

Take function in variable

foo = setTimeout(function, time);

and then just clear it out

clearTimeout(foo);

I hope this will help you

Upvotes: 1

Related Questions