hurriedly% 2016-08-10 06:40 采纳率: 100%
浏览 17

加载变化的div

I am creating a question and answer site.

Currently, two users can log into the site and have access to one page. I tried using the jquery.load function to show both users the same page. The problem is that I have buttons on the page and I want that when one user presses a button the other can see it change (these are not 'submit' buttons they just change color on press).

If I am correct it seems the .load function only loads the static code on a page. Is there a way to make both parties see changes the other makes without refreshing the page? So if one user changes something in a div, the other user has to see it.

    jQuery(document).ready( function($){
    $('#Submission-2').load('http://example.com #div');

I am new to jquery as well (started only a few days ago).

Currently, two users can create a 'party'. the party url has both users usernames in it like www.example.com/?user1=user1&user2=user2. Once both these users are logged in and there is a party created for them. This is when I need them to access the same page. BTW I am using Wordpress.

When the first user submits data I add it to the session and both users can see that information fine. The problem is when the second user has to select information(press buttons) for that submitted information the first user won't see those changes.

  • 写回答

1条回答 默认 最新

  • weixin_33709219 2016-08-10 07:27
    关注

    You can achieve this by using the setInterval function like this

    setInterval(function(){
        $('#Submission-2').load('http://example.com')
    },3000);
    

    This sends a HTTP request to the page every 3 seconds and the result fetched will be displayed in the given div

    BROAD ALTERNATIVE

    Depending on your question this can be achieved by

    1. Long Polling
    2. Server-Sent Events
    3. Websockets
    4. Comet

    You can have your answer to these depending on the answer given to this question: What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示