[英]Is there any way to make it so that Python processing is performed even if the button is "Open New Tab" via Ajax
I am trying to prevent the user from moving to the manager class target link by using Ajax, but I am facing a problem that if I right-click to open a new tab or open in a new window, the user can move to the target link.我试图通过使用 Ajax 阻止用户移动到经理 class 目标链接,但我面临一个问题,如果我右键单击以打开新选项卡或在新的 window 中打开,用户可以移动到关联。
By the way, the JS is written as follows, and when the button is pressed, Ajax is activated.顺便把JS写成如下,当按下按钮时,Ajax被激活。
$('#button').click(function () {
const url = '//login?id=', userId);
$.ajax({
url: url,
contentType: 'application/x-www-form-urlencoded',
type: 'GET',
async: false,
})
.then(function (data) {
const nextUrl = data.url;
if (transferUrl) {
location.href = nextUrl;
} else {
alert('No Authorization');
}
})
.catch(function () {
alert('Failed');
});
The button HTML is written as follows.按钮 HTML 编写如下。
<a id="button" href="/admin/top.html">
<img id="toplnk" src="/images/login/a.png" onmouseover="this.src='/images/login/b.png'" onmouseout="this.src='/images/login/c.png'" alt="page">
</a>
The Python code that is sent and processed by Ajax is as follows. Ajax发送并处理的Python代码如下。
def check_user(self, request):
user_id = request.GET.get(key='id')
user = User.objects.all().filter(Q(UserId__exact=user_id), condition_role)
if user.count() == 0:
url = ""
else:
url = '/admin/top.html'
json_data = {'url': url}
return Response(json_data)
Is there any way to make it so that Python processing is performed even if the button is "Open New Tab" via Ajax as shown above?有什么办法可以使 Python 处理即使通过 Ajax 按钮是“打开新标签”,如上所示?
There can be a couple of solutions, you need to decide which one would suit your usecase.可能有几种解决方案,您需要决定哪一种适合您的用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.