1

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
Matarishvan
  • 2,382
  • 3
  • 38
  • 68
  • What do you mean when you say _"Then i'l change my URL to"_? What purpose are you changing it for and at what point? – Jamie Barker Feb 11 '15 at 11:40
  • you can use setInterval or press F5 for each 5 seconds in your browser. –  Feb 11 '15 at 11:52

4 Answers4

1

You can make second function

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

this might solve.

1

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);
user2232273
  • 4,898
  • 15
  • 49
  • 75
1

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

Federico
  • 1,231
  • 9
  • 13
  • `window.location.pathname` would be better suited for this use case, avoiding all sorts of issues to do with loading a full domain rather than a relative path. – Connor Burton Feb 11 '15 at 11:47
  • even better would be to change the table content with an Ajax request.... and avoiding using the url..... – Federico Feb 11 '15 at 11:48
1

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);
Jai
  • 74,255
  • 12
  • 74
  • 103