调用PHP函数与AJAX,但重定向不能正常工作

编程入门 行业动态 更新时间:2024-10-24 20:16:37
本文介绍了调用PHP函数与AJAX,但重定向不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个是把我的头一个问题。我会说明情况......我正在与opencart一个项目,我创建了一个按钮的工作原理是这样的:当你点击它,它应该发送给网站的所有者一切都购物车中,并这些产品一起去客户数据,并且只可以发送电子邮件,如果用户登录,那么这个问题开始。

I have a problem that is turning my head. I will explain the situation... I'm working on a project with opencart, and I created a button that works like this: when you click on it, it should send to the website owner that everything is within the shopping cart, and these products go together customer data, and only can send the email if the user is logged in, then the problem starts.

这是该按钮,其客户会点击:

This is the button where the customer will click:

<div class="checkout-button"><a id="button-quotation" class="button">click me</a></div>

再通过AJAX将调用PHP函数来检查这一点:

Then through the AJAX will call the PHP function to check for this:

$(document).ready(function(){ $('#button-quotation').click(function(){ var clickBtnValue = $(this).val(); var ajaxurl = 'index.php?route=checkout/cart/quotation', data = {'action': clickBtnValue}; $.post(ajaxurl, data, function (response) { alert("works!!"); }); });});

在这里,有一个重定向功能,将发送给客户端的登录页面,如果没有登录:

And here there is a redirect function that will send the client to the login page, if it is not logged:

public function quotation(){ if (!$this->customer->isLogged()) { $this->session->data['redirect'] = $this->url->link('checkout/cart', '', 'SSL'); $this->redirect($this->url->link('account/login', '', 'SSL')); } }

我可以使邮件工作,但我不能运行重定向如果没有登录到该网站的客户端。有人能帮助我吗?

I can make the emails work, but I can not run the redirect if the client is not logged into the site. Someone can help me please?

推荐答案

如果你在你的PHP函数重定向只有AJAX请求将会被重定向。

If you redirect in your PHP function only the AJAX request will be redirected.

你应该做的:让函数返回的数据,指示JavaScript的,它应该发出一个重定向到登录页面

What you should do: let the function return data that indicates the JavaScript that it should issue a redirect to your login page.

也看到这一问题:How管理一个jQuery的Ajax调用后重定向请求

See also this question: How to manage a redirect request after a jQuery Ajax call

更多推荐

调用PHP函数与AJAX,但重定向不能正常工作

本文发布于:2023-10-12 17:24:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485377.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不能正常   函数   重定向   工作   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!