0

After refreshing.....it goes on to the main page but not on the current page. What to do if it will be on the same page after refreshing. I have one index.html page but with 6 swiper slides...

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function autoRefresh_div()
{
    $("#MyDIV").load("load.html");// a function which will load data from other file after x seconds
}
setInterval('autoRefresh_div()', 5000); // refresh div after 5 secs
</script>
Milap
  • 6,915
  • 8
  • 26
  • 46
  • Maybe this article can help http://stackoverflow.com/questions/19370417/how-to-load-external-html-into-a-div – ikos23 Feb 22 '16 at 07:25
  • 1
    try to remove "'" : setInterval(autoRefresh_div, 5000); the first parameter is a function. – Jurion Feb 22 '16 at 07:27
  • whats the error you get now? – Rajshekar Reddy Feb 22 '16 at 07:30
  • After refreshing?? what, the page? this does not alter the html page file ($("#MyDIV").load("load.html");) but the DOM in memory – Tasos Feb 22 '16 at 07:31
  • its not an error....its refreshing but after refreshing it goes on the main page instead of current page.....there 6 swiper slides in one html page – Deepak Jadhav Feb 22 '16 at 07:32
  • empty the div 1st before you load ($("#MyDIV").empty();) – Tasos Feb 22 '16 at 07:34
  • check your `load.html` page, may be the page has some content for that the page goes to `main page`. and remove the quota from `setInterval` and also the function sign. – Murad Hasan Feb 22 '16 at 07:37

1 Answers1

0

I hope this would be helpful.

Index.html

<!DOCTYPE html>
<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <link href="style.css" rel="stylesheet" />
  </head> 
  <body>
    <div id="myDiv">Loading...</div>
  </body>
  <script src="script.js"></script>
</html>

script.js

<script>
    setInterval(function(){
      $("#myDiv").load("sample.html");
    }, 1000);
</script>

Example: http://plnkr.co/edit/jgIMZ9Y1l167VHFg32Ik?p=preview

MasoodRehman
  • 715
  • 11
  • 20