This question already has an answer here:
- Page redirect with successful Ajax request 10 answers
What i am trying to do here was to pass the form values to a function in controller via jquery ajax post upon submit.
here's the code for the view
<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>
The controller will process the post variables then should execute this line of code $this->paypal->pay();
that will redirect the user to other url.
Here's the code for a function in the controller (products.php)
public function paypal() {
//... paypal configuration
$this->paypal->pay(); //Proccess the payment
}
Here's the code for a function in the library (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);
}
}
The problem is that the user is not being redirected. What could be the problem in this one?
Thanks in advance.
</div>