sushibrain
sushibrain

Reputation: 2780

.load() makes all ajax loaded divs refresh

I'm currently working on a project which involes a couple of constantly reloading divs. In this case, every 10 seconds. This I've done through the following code:

$(document).ready(function() {
    $("#radiostatusInner").load("/public/assets/scripts/radiostatus.php");
    setInterval(function() {
        $("#radiostatusInner").load("/public/assets/scripts/radiostatus.php");
    }, 10000);
});

I load it at page load, and then refresh it every 10 seconds. Now the problem are my AJAX loaded pages. Every interval of the above code, the ajax loaded page refreshes, which is highly annoying. Especially when filling out a form of some sort, since it will empty itself.

This is the code I use to load pages:

$.ajax({
    type: "GET",
    url: "/public/assets/scripts/pagina.php",
    data: 'page=' + url, // url variable is defined above this snippet.
    dataType: "html",
    success: function(msg) {
        if (parseInt(msg) != 0) {
            $('.mainContent').html(msg);
        }
    }
});

So is there any way these two are interfering with each other? And if so, how to I resolve this issue?

Upvotes: 0

Views: 41

Answers (1)

Vidya Sagar
Vidya Sagar

Reputation: 1719

$(document).ready(function() {
     $("#radiostatusInner").load("/public/assets/scripts/radiostatus.php");
   var refreshId = setInterval(function() {
      $("#radiostatusInner").load('/public/assets/scripts/radiostatus.php?randval='+ Math.random());
   }, 10000);
   $.ajaxSetup({ cache: false });
});

check this link, might it may give you some idea..

Upvotes: 1

Related Questions