0

I'm trying to call another page called bidtable.php inside a div and I want it to refresh in every 20 seconds. Here is what I've tried but It's not working.

<script src="http://code.jquery.com/jquery-latest.js"></script>
<div class="row justify-content-center">
  <div id="latestData" class="row justify-content-center col-md-5" style="background-color: black; margin: 2px auto; width: 370px;"></div>
</div>
$(document).ready(function() {
  refreshTable();
});

function refreshTable() {
  $('#latestData').load('bidtable.php', function() {
    setTimeout(refreshTable, 20000);
  });
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • Firstly check the console for errors with the AJAX request. Secondly, note that AJAX polling is not a scalable solution. If you need to keep the client and server side in close sync use Websockets. – Rory McCrossan Jan 15 '20 at 16:16
  • If you are using modern browsers it may block by CORS policy. check your console. is it? – Ali Maleki Jan 15 '20 at 16:29
  • Actually It was running perfectly when I tasted it with my localhost/phpmyadmin but now the site is live and It's not working. Can you suggest me any other idea to solve this problem?? Please. –  Jan 15 '20 at 17:15
  • Does this answer your question? [How to load PHP file into DIV by jQuery?](https://stackoverflow.com/questions/12524228/how-to-load-php-file-into-div-by-jquery) – Juan Marco Jan 15 '20 at 22:38

1 Answers1

0

Try by adding the URL to the PHP file instead of just the file name. Like this:

function refreshTable() {
  $('#latestData').load('the_url/bidtable.php', function() {
    setTimeout(refreshTable, 20000);
  });
}
Juan Marco
  • 3,081
  • 2
  • 28
  • 32
  • I had the same idea so I tried that yesterday but that didn't work too. Do you have any other idea that can help to solve the problem? Basically, on 'bidtable.php' page, I'm showing 14 different tables with conditions and I want to show the contents of 'bidtable.php' page in a div so that user can see the contents according to the conditions applied to him. –  Jan 16 '20 at 05:26
  • Humm, is `bidtable.php` in the root folder of the website or is it placed in another folder? – Juan Marco Jan 16 '20 at 13:11
  • It is in the root folder. I solved the problem though. I declared the script source after defining the function and that's exactly where I was doing it wrong. Now I've decided to declare all the sources inside the header then define and call any function anywhere inside the body or the header. Please excuse my silly mistake. –  Jan 17 '20 at 11:40
  • Glad to hear you got it working! – Juan Marco Jan 17 '20 at 12:47