【发布时间】:2015-02-28 07:03:27
【问题描述】:
我在这里尝试做的是在提交时通过 jquery ajax post 将表单值传递给控制器中的函数。
这是视图的代码
<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>
控制器将处理 post 变量然后应该执行这行代码 $this->paypal->pay(); 将用户重定向到其他 url。
这是控制器中函数的代码(products.php)
public function paypal() {
//... paypal configuration
$this->paypal->pay(); //Proccess the payment
}
这是库 (Paypal.php) 中函数的代码
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);
}
}
问题是用户没有被重定向。这可能是什么问题?
提前致谢。
【问题讨论】:
标签: javascript php jquery ajax codeigniter