4

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.

Dario
  • 145
  • 1
  • 10

1 Answers1

1

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?

Community
  • 1
  • 1
KANAYO AUGUSTIN UG
  • 2,078
  • 3
  • 17
  • 31