Redirect with PHP after ajax call

Solution 1:

You redirect in success:

$('#save_sale').click(function() {
    var save_sale = 1;
    $.ajax({
        type: 'GET',
        url: 'summary.php',
        data: {save_sale: save_sale},
        success: function(data) { 
                window.location.href = 'addcust.php?new_sale=' + data
            },
        error: function(xhr, ajaxOptions, thrownerror) { }
    });
});

Whatever you echo back from the PHP script will be in data. So echo $sale_id and you'll have your URL.

Solution 2:

You can use JavaScript to redirect in the success handler:

success: function(data) { 
    window.location = 'newpage.php';
},

It can't be done with a PHP redirect, because that will only redirect the ajax call, not the original browser window.

If you want to use the sale ID in the URL then you will need to output it so it can be accessed:

$saleId = $new_sale->id; // or however you get the sale ID
echo json_encode(array('saleId' => $saleId)); // output JSON containing the sale ID

Ajax:

$.ajax({
    type: 'GET',
    url: 'summary.php',
    dataType : 'json', // tell jQuery to parse the response JSON
    data: {save_sale: save_sale},
    success: function(data) {
        window.location = 'addcust.php?new_sale=' + encodeURIComponent(data.saleId);
    },
    error: function(xhr, ajaxOptions, thrownerror) { }
});

Solution 3:

on your js page

 $.ajax({
        type: 'GET',
        url: 'summary.php',
        data: {save_sale: save_sale},
        //success: function(data) { /* Do something here?? */ },
        error: function(xhr, ajaxOptions, thrownerror) { }
    }).success(function(data) {
       window.location('addcust.php?new_sale='+data.id)
    });

on your php script echo the id

$data['id'] = <sale_id>;
echo json_encode($data);exit

hope it will work.