Rickstar
Rickstar

Reputation: 6199

Page changed in JQUERY

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

Upvotes: 1

Views: 130

Answers (4)

Drew Wills
Drew Wills

Reputation: 8446

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.

Upvotes: 1

JP Silvashy
JP Silvashy

Reputation: 48555

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.

Upvotes: 0

Malfist
Malfist

Reputation: 31815

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)

Upvotes: 0

Pekka
Pekka

Reputation: 449843

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

Upvotes: 4

Related Questions