Reputation: 511
I have the script below that works great but want to modify it for a desired effect. Right now it only works on initial page load. But how can I edit it to make it auto-feed every 30 seconds or so?
$.ajax({
type: "GET",
url: "Administration/data/people.xml"
}).done(function (xml) {
$(xml).find('fullName').each(function() {
var fullName = $(this).text();
$('<button type="button" class="mybutton" name="users" onclick="showUser(this.value)"></button>').attr('value', fullName).html(fullName).appendTo('#loadMe');
});
}).fail(function (response, error) {
$('#info').text('Error!');
});
EDIT: 1/24/14 3:55 AM
I added the interval function, but now it is on an infinite loop and is not overwriting, but instead adding over and over again.
$(document).ready(function(){
setInterval(updateMe,1000);
function updateMe(){
$.ajax({
type: "GET",
url: "Administration/data/people.xml"
}).done(function (xml) {
$(xml).find('fullName').each(function() {
var fullName = $(this).text();
$('<button type="button" class="mybutton" name="users" onclick="showUser(this.value)"></button>').attr('value', fullName).html(fullName).appendTo('#loadMe');
});
}).fail(function (response, error) {
$('#info').text('Error!');
});
}
});
Upvotes: 0
Views: 68
Reputation: 44814
have a look at javascript setInterval ()
Plenty of examples on the web but the basic syntax is
var intervalID = window.setInterval(code, delay);
Upvotes: 1
Reputation: 33186
Use the setInterval function to call the function every 30000 miliseconds.
Upvotes: 1