Sunday, 15 July 2012

javascript - Reload page if modified on server -



javascript - Reload page if modified on server -

i trying create page reload if has changed on server, ajax requesting page's own url every second, , checking if textstatus notmodified.

settimeout(function(){ $.ajax({ url : window.location.pathname, datatype : "text", ifmodified : true, success : function(data, textstatus) { if (textstatus !== "notmodified") { location.reload(); } } }); }, 1000);

however, textstatus success

just seek random variable avoid caching of response, itself. also, replace !== !=.

settimeout(function(){ $.ajax({ url : window.location.pathname + "?" + (new date()).getmilliseconds(), datatype : "text", ifmodified : true, success : function(data, textstatus) { if (textstatus != "notmodified") { location.reload(); } } }); }, 1000);

if doesn't work, seek replacing:

location.reload();

with:

location.href = location.href;

this depends on server side script. needs sent server side... setting no-cache , content-expires.

javascript jquery http

No comments:

Post a Comment