-1

I found this similar question but i don't think it solves my problem. For my scenario I have updating / saving of data in my project.

SCENARIO

Filer wants to update his/her record in (PC1)

Then the (PC2) is already open the page for the list of the pending request.

What I want is after every a request from (PC1) the page in (PC2) will automatically refresh if it is currently open - no need for the user to manually reload (e.g. by pressing F5).

Community
  • 1
  • 1
Dave
  • 75
  • 1
  • 1
  • 9

2 Answers2

1

You can achieve this by different methods like:

  • long polling: long polling is kinda event driven notifying where sever responds back when there is a change (holds the request until data is available)
  • Short polling - Periodically (for eg, every 30 seconds) hitting the server with ajax request to get fresh data

Both the above techniques are old and not recommended now as you have latest features like HTML5 WebSockets and WebRTC in modern browsers. What you need here is a push from server side whenever there is a change.

I would recommened you to have a look into SignalR (http://www.asp.net/signalr) if you are using dotnet backend or if its node backend, then node implementation of signalr (npmjs.com/package/signalrjs).

ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization.

Update - Just saw an awesome detailed explanation in SO which would give you more insight (may be the question is different, but the answer given is something which would help you) - In what situations would AJAX long/short polling be preferred over HTML5 WebSockets?

Community
  • 1
  • 1
Developer
  • 6,240
  • 3
  • 18
  • 24
0

See How to refresh another page using javascript without opening the same page in a new tab.

Basically what you need to do is:

//somewhere in your code you open a new tab
//maintain a reference to the window
var childWindow = window.open(initialURL);

//anywhere in your code, when you need to change the url of the window
//if you want to refresh that page, simply use newURL = initialURL
child.location.href = newURL;
Community
  • 1
  • 1
Tan Li Hau
  • 1,984
  • 17
  • 24
  • I am trying your suggestion [here](https://jsfiddle.net/kqLqnkdw/) but refresh not working – Dave Sep 19 '16 at 03:22
  • "VM329:77Unsafe JavaScript attempt to initiate navigation for frame with origin 'https://www.google.com.sg' from frame with URL 'https://fiddle.jshell.net/_display/'. The frame attempting navigation is sandboxed, and is therefore disallowed from navigating its ancestors." You should try it on your web app – Tan Li Hau Sep 19 '16 at 03:54
  • Is there any site that can i test it first before I use it in my project?. – Dave Sep 19 '16 at 03:56
  • @Dave - `PC1` and `PC2` in your question means two different users in two different computers, is it? – Developer Sep 19 '16 at 04:51
  • @Developer yes. It is possible to refresh? – Dave Sep 19 '16 at 05:08
  • @Dave - I'm not sure in that case the above approach would work. IMO you should be looking for something like SignalR. What is your backend technology btw? – Developer Sep 19 '16 at 05:17
  • @Developer I don't quite understand the signalr. And I dunno how to embed the codes into my project – Dave Sep 19 '16 at 05:31