2

Now I have a php page "userreq.php" managed by a angular js controller.On a button click I am calling a funcion which posts the data to another php page "checkout.php".

$http({
        url: "checkout.php",
        method: "POST",
        data: {
            data: variable
        }
    }).success(function(response) {
    console.log(response);
});

This is how I am posting it.Now I want the page to navigate to checkout.php after the variable has been posted so that I can work with that variable in checkout.php. How can I achieve that.

7
  • you could use window.location.href = 'url'; in your success function. developer.mozilla.org/en-US/docs/Web/API/Window/location Commented Feb 14, 2016 at 8:31
  • but it is redirection right http post will have no effect..I am new to angular so I may be wrong Commented Feb 14, 2016 at 9:14
  • depends on what you want, you could simply pass params with window.location instead of using ajax Commented Feb 14, 2016 at 9:16
  • $scope.checkout = function(){ $http({ url:"checkout.php", method : 'POST', data :{ total:$scope.total }, headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'} }).success(function(data, status, headers, config) { window.location.href="checkout.php"; }).error(function(data, status, headers, config) { console.log("not done"); }); } and in checkout.php i am doing <?php $var = $_POST['total'];?> but i am getting error that total is not defined Commented Feb 14, 2016 at 9:20
  • 1
    thanks for the help sir..but actually i need to pass an array Commented Feb 14, 2016 at 9:33

1 Answer 1

0

Add the $httpParamSerializerJQLike in your controller and pass your data as query parameters.

Example :

var url = 'checkout.php'; 
var data = { id: 1, name: 'foo' };

$http({
    url: url,
    method: "POST",
    data: data
})
.success(function(response) {
    console.log(response);
    window.location.href = url + '?' + $httpParamSerializerJQLike(data);
});

And in your php, retrieve the data from $_GET :

$field = $_GET[$field];
// Output: array( 'id' => 1, 'name' => 'foo' )
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.