0

It is related to the question here: How to load some html and append to <body> with jQuery?

I been asked to open new question

my problem is:

I have small datepicker that show the current date and the next day. I used the code posted there, but having problem, the problem is that the data is not update, but when I refresh the page it update. I using wordpress and plugin allow to run jQuery

the code that posted there is

$.ajax({
    url: "your.html",
    success: function (data) { $('body').append(data); },
    dataType: 'html'
});

How can I fix this?

Community
  • 1
  • 1
hanan-mstudio
  • 172
  • 1
  • 2
  • 15
  • Inside the success callback, add on console.log(data); Your data result may not be up to date. – roland Jan 25 '15 at 07:45
  • Not a short answer for this one. Must it update on a click, on a hover, on a timer? When must it update? All the answers for each case are simple, but different. – Gavin Simpson Jan 25 '15 at 07:50
  • r u sure that ur ajax call is returning html ? put a `console.log(data)` in ur success function and check in console in DevTools if its fine – Arkantos Jan 25 '15 at 07:52
  • I need the show the datepicker every time someone visit the page. I insert it into the (document).ready(function() section, but it not showing the correct date until I refresh the page but sometime it showing it on the first try – hanan-mstudio Jan 25 '15 at 10:49

1 Answers1

1

this may help
this will automatically update the code after every 200ms after the page is loaded

$(document).ready( function() {
 done();
});

function done() {
  setTimeout( function() { 
  updates(); 
  done();
  }, 200);//set timer 

}

function updates() {
     // add your code here to update

}

Pushkarraj Pujari
  • 666
  • 11
  • 25
  • `setTimeout()` will invoke a function only once. You have to use `setInterval()` to invoke some function at regular intevals :) . Although there's no guarantee it will invoke for every 200ms, that's the minimum it waits to invoke that function, it can be even more - depending your whether your JS thread is busy doing something else – Arkantos Jan 25 '15 at 08:07