Matarishvan
Matarishvan

Reputation: 2432

Refresh table for every 5 seconds for a specific URL

Basically i have a dynamic HTML table

<table id="example"></table>.

The contents inside the table changes based on the URL. My default URL will be

index.php?action=add

For this i have written a function to refresh my table for every 5 seconds, which works fine

var autoLoad = setInterval(
function ()
{
   $('#example').load('index.php?action=add #example').fadeIn("slow");
}, 5000);

Then i'l change my URL to

index.php?action=add&subdo=loc.

This will change the contents inside my HTML table.

So how do i refresh the new contents for every 5 seconds in my HTML table for index.php?action=add&subdo=loc

EDIT : I will have to change to multiple URL's for different contents in my TABLE for different URL's. NOT one

index.php?action=add&subdo=loc1
index.php?action=add&subdo=loc2

Upvotes: 1

Views: 1713

Answers (4)

user2232273
user2232273

Reputation: 4974

use window.location.search

try this: UPDATE

var autoLoad = setInterval(
function ()
{
   var url = window.location.search;
   $('#example').load('index.php' + url + ' #example').fadeIn("slow");
}, 5000);

Upvotes: 1

Jai
Jai

Reputation: 74738

Try this:

var url = '',
  autoLoad = setInterval(function() {
    if (window.location.pathname.indexOf('subdo') != -1) {
      url = 'index.php?action=add&subdo=loc';
    } else {
      url = 'index.php?action=add';
    }
    $('#example').load(url + ' #example').fadeIn("slow");
  }, 5000);

Upvotes: 1

Federico
Federico

Reputation: 1251

If I understand right when you change the url in the browser the script remain the same...

did you try using the window.location like:

$('#example').load(window.location.href).fadeIn("slow");

this way the interval will re-call the current url whatever it is.

Let me know...

Upvotes: 1

Syed ObaidUllah Naqvi
Syed ObaidUllah Naqvi

Reputation: 474

You can make second function

var autoLoad2 = setInterval(
function ()
{
$('#example').load('index.php?action=add&subdo=loc #example').fadeIn("slow");
}, 5000);

this might solve.

Upvotes: 1

Related Questions