如何规范化多个标签的ajax调用?

时间:2022-12-02 18:05:05

I have created application in which on each page at header loading the notifications, messages using the ajax call.

我创建了一个应用程序,在每个页面上的标题加载通知,使用ajax调用的消息。

I have repeated the action with difference of half minute.

我重复了半分钟的动作。

So after every half minute the new request to server has initiated.

因此,每隔半分钟就会启动对服务器的新请求。

I found that if user open the application in multiple tabs then each tab fire the request to server for the new notification/message check.

我发现如果用户在多个选项卡中打开应用程序,则每个选项卡都会向服务器发出请求以进行新的通知/消息检查。

So each new tab create 1 extra requests.

因此,每个新标签创建1个额外请求。

How do I normalize the condition?

我如何使病情正常化?

I mean to say---I just want to fire the single request to server for the notification/message check all-thought user open multiple tab and also update the data in each opened tab of application.

我的意思是说 - 我只是想向服务器发出单个请求以通知/消息检查全思考用户打开多个选项卡,并且还更新每个打开的应用程序选项卡中的数据。

2 个解决方案

#1


2  

Maybe u can check with focus blur which tab is active and only send request from the active tab and store the result in localstorage. And add a EventListener to localstorage so that u can update the other tabs.

也许您可以使用焦点模糊检查哪个选项卡处于活动状态,并且仅从活动选项卡发送请求并将结果存储在localstorage中。并将EventListener添加到localstorage,以便您可以更新其他选项卡。

#2


1  

Maybe for each parameter you could store its value and a timestamp in a cookie and check it before your send your request. You could also use local storage to do that. http://www.html5rocks.com/en/features/storage

也许对于每个参数,您可以将其值和时间戳存储在cookie中,并在发送请求之前进行检查。您也可以使用本地存储来执行此操作。 http://www.html5rocks.com/en/features/storage

#1


2  

Maybe u can check with focus blur which tab is active and only send request from the active tab and store the result in localstorage. And add a EventListener to localstorage so that u can update the other tabs.

也许您可以使用焦点模糊检查哪个选项卡处于活动状态,并且仅从活动选项卡发送请求并将结果存储在localstorage中。并将EventListener添加到localstorage,以便您可以更新其他选项卡。

#2


1  

Maybe for each parameter you could store its value and a timestamp in a cookie and check it before your send your request. You could also use local storage to do that. http://www.html5rocks.com/en/features/storage

也许对于每个参数,您可以将其值和时间戳存储在cookie中,并在发送请求之前进行检查。您也可以使用本地存储来执行此操作。 http://www.html5rocks.com/en/features/storage