简体   繁体   English

如果用户重新加载/重定向页面,js发送发布请求

[英]js send post request if user reloads/redirect page

In my project I collect statistics about users but if he click some link in page and this page opened in current page my post request is interrupted. 在我的项目中,我收集有关用户的统计信息,但是如果他单击页面中的某个链接,并且此页面在当前页面中打开,则我的发帖请求会中断。

Maybe exists some "hacks" for send request, but just with use JS and not some else. 也许存在一些发送请求的“ hacks”,但仅使用JS而不是其他一些。

Because you asked for hacks, 因为您要求黑客入侵,

If it is possible, just add a target="_blank" on anchor tags to open the clicked resource so that it opens up in new tab instead of the existing. 如果可能的话,只需在锚标记上添加target="_blank"即可打开单击的资源,以便在新选项卡(而不是现有选项卡)中打开它。

If opening a new link via a js function, use window.open instead to avoid opening in current window. 如果通过js函数打开新链接,请改用window.open以避免在当前窗口中打开。

You may use something like AJAX, sending the post in any asyncronous way. 您可以使用AJAX之类的方法,以任何异步方式发送帖子。

You have more info in this link: 您在此链接中有更多信息:

http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM