Response title
This is preview!
globalVar.firstRequest = true;
globalVar.lastModifiedDate;
$.articlePoller = {
poll: function() {
console.log('Ran poll');
setTimeout(this.request, 5000);
},
request: function() {
console.log('Ran request');
var dataUrl = $('#articles').data('url');
$.ajax({
url: dataUrl,
type:"GET",
cache: true,
ifModified: true,
Async: true,
beforeSend: function(xhr){
if(!globalVar.firstRequest) {
// HELP!!!
xhr.setRequestHeader("If-Modified-Since", globalVar.lastModifiedDate);
}
},
success: function(html, textStatus, xhr){
if(globalVar.firstRequest) {
console.log('First request');
globalVar.firstRequest = false;
globalVar.lastModifiedDate = xhr.getResponseHeader('Last-Modified');
// Start again
$.articlePoller.poll();
} else {
console.log('Subsequent request');
// HELP!!!
if(???) {
console.log('We have change! Proceeding to fetch the actual content...');
$.articlePoller.addArticles();
}
}
}
});
},
addArticles: function(articles) {
// ...
},
showArticles: function(e) {
// ...
}
};
$(function() {
$.articlePoller.poll();
$('#show_articles a').click($.articlePoller.showArticles);
});
jQuery is just so much prettier and easier to understand.
Thanks!
Frank
© 2013 jQuery Foundation
Sponsored by and others.