alert another page

I have an index.php. It has a log in function. Let’s say I have 2 users A and B.Page1(index.php of user A) -with function(checks whether there are changes in the database, if yes: alert(‘message’))Page2(index.php of user B) -with button which when clicked should update the databaseI can already update the database, the …

via PHP Website Development » Search Results » ajax:

alert another page

I have an index.php. It has a log in function. Let’s say I have 2 users A and B.
Page1(index.php of user A) -with function(checks whether there are changes in the database, if yes: alert(‘message’))
Page2(index.php of user B) -with button which when clicked should update the database
I can already update the database, the function from page1 already works, it can detect changes, but only when you reload it. So I want to reload Page1 whenever page2 updates the database. I thought of just using setTimeout(something, timeInterval) in Page1 but it doesn’t seem appropriate since the components of Page1 are flickering everytime it reloads. I want Page1 to reload if and only if there are changes in my database. I also thought of just putting the Page1′s function inside an infinite while loop but it doesn’t seem appropriate either, since the page just loads..
Another thing is, I was informed about JSON and REST. So I could just access the database from the script file. But I’m not that knowledgeable in it. Neither am I in jQuery.
I’ve tried searching about refreshing a page from another but the answers I found were either vague or difficult for me. And my pages have the same name, they only differ with the user logged in. But If I can find a way to do this, then I’ll just do something with my pages’ names.
Is there any other way I can do this? Thank you.
…………………………………..

So you basically need for the server to notify page1 when an update is available. What you are looking is called “comet”. Check out this articles:
comet wikipedia
comet ajaxian
Comet programing can be done using ajax or iframes
…………………………………..

When the page you want to update first loads, put the time in a variable by doing
something = new Date().getTime();
Send an XMLHttpRequest to a php that checks if the databases last update time is newer than the time sent with the ajax call. If it is, return something that tells the javascript to refresh the page. If not, have the javascript make another call in a few seconds with setTimeout .
It would be better if you learned the ropes of javascript before using jQuery, so I’ll update this answer in a second with some script.
edit 1: check out https://developer.mozilla.org/en/AJAX/Getting_Started
Using jQuery for ajax calls is one of the most sensible uses of jQuery, but it’s better if you know how it works too.
…………………………………..

Create pageC.php which should check if database has changed, and if so, output 1, else output nothing.
Then with jQuery and AJAX…








For more info: alert another page

PHP Website Development » Search Results » ajax

alert another page

Share this post:

Related Posts

Leave a Comment