Ajax request header saved

I have an Ajax request to refresh the client page if any new data is available to the server. I made a 'keep-Alive' connection 'keep-Alive' So, every time I do not make a new Ajax call to check for updated data. I have a callback that refreshes the page if there are entries.

Below is my Ajax request .

 xmlRequest.open("post", url, true); xmlRequest.setRequestHeader("Connection", "Keep-Alive"); xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); xmlRequest.send(some data); 

It works fine, but if the user updates the browser, Ajax will not receive the updated data from the server.

My concept is not entirely clear how the "keep-Alive" connection type works. but it seems that when the user updates the browser and then the Ajax connection is lost on the server, Ajax stops listing.

I know that I can fix this by making a new call when the browser refreshes the page. but here I want to understand if this Ajax keep-Alive really lose connection when updating the browser.

+7
source share
1 answer

Normally, the javascript environment is cleared on the reset page, but you can use window.localStorage to continue updating and maintaining the xmlRequest variable. You can then test the client + server side to see if you need to reinitialize the connection.

0
source

Source: https://habr.com/ru/post/955779/


All Articles