douren9077 2011-10-01 07:23
浏览 11

提醒另一页

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.

  • 写回答

3条回答 默认 最新

  • dongrouli2667 2011-10-01 07:29
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度