tags:

views:

59

answers:

4

I am trying to found out how to see if a php file has changed and then show a div with saying Page changed in JQUERY

+4  A: 

You'd better do that in PHP using filemtime, no need for JQuery here.

Pekka
Yep. jQuery's awesome and all, but there are situations in which it's not the answer.
ceejayoz
A: 

Javascript cannot access the server, you will have to use some sort of server side technology. Like PHP that was suggested by Pekka.

In short, javascript is client side, which means it interacts with the user on their side, while php is server side, meaning it interacts with the server. Checking the file modified date is a server side issue, your client isn't serving the pages (unless you're on freenet)

Malfist
A: 

Or you could output a <meta> tag for when the page was updated with PHP or whatever framework or language you are using. Then create a cookie with your JS and compare the cookie with the meta tags content.

Ugly solution but it would work. I wouldn't want to resort that this however.

Joseph Silvashy
+1  A: 

You only need jQuery for this task if you're trying to detect the page change without waiting for the user to request a new page. If not, do as the other responder suggests and use PHP.

But if you need to do it without a page reload, use one of the $.ajax() methods in jQuery in combination with a JavaScript timer. You'll have to poll the server periodically (thus the timer) to ask if the page has been altered.

You would also need to set up something on the server that can tell your page about changes. Perhaps a very simple service that provides the timestamp of the last edit in JSON format. Use $.ajax() to poll for the timestamp, then compare it with the last edit the page knows about. If the timestamp from JSON is more recent, display your div.

Drew Wills