Javascript 服务器立即返回ajax post,而不执行重定向代码
我在这里试图做的是在提交时通过jQueryAjax post将表单值传递给controller中的函数 下面是视图的代码Javascript 服务器立即返回ajax post,而不执行重定向代码,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,我在这里试图做的是在提交时通过jQueryAjax post将表单值传递给controller中的函数 下面是视图的代码 <form action="<?php echo site_url('products/paypal')?>" method="post" id="checkoutForm" name="checkoutForm"> ... </form> <script type="text/javascript"> ...
<form action="<?php echo site_url('products/paypal')?>" method="post" id="checkoutForm" name="checkoutForm">
...
</form>
<script type="text/javascript">
...
$.post($('#checkoutForm').attr('action'), $('#checkoutForm').serialize());
...
</script>
以下是库中函数的代码(Paypal.php)
问题是用户没有被重定向。这个有什么问题吗
提前感谢。如果从客户端提交Ajax表单,您将永远无法从服务器执行浏览器重定向。这就是常规请求和Ajax请求之间的区别。您需要定期提交表单,或者在Ajax调用返回后更改客户端的窗口位置
public function paypal() {
//... paypal configuration
$this->paypal->pay(); //Proccess the payment
}
function pay(){
#Convert the array to url encode variables
$vars = http_build_query($this->config);
if($this->config['production'] == TRUE){
header('LOCATION:'.$this->production_url.$vars);
}else{
header('LOCATION:'.$this->sandbox_url.$vars);
}
}