Garg Garg - 1 year ago 84
PHP Question

Redirect back to previous page doesn't work as expected

I have url which looks like

When I click to see second page it becomes like

When I delete product from category I want to redirect me back to same page and I've using

header('Location: ' . $_SERVER['HTTP_REFERER']);

This works when I'm on first page but if I'm on second or another page ?pageno=2&parent=257 it redirects me to &parent=... it's loosing pageno=...

I've tried a lot of solutions here on so but all redirect me back to parent.

I've tried also like this:


but this doesn't refresh the page and I need to refresh it in order to see the result.

Actually ideally should refresh the page and stay on same page..

function deleteproduct(prodid) {
if(confirm('Are you sure you want to delete this product')) {
window.location = "del_product.php?act=del&masterCategory=<?=$parent?>&subCategory=<?=$child?>&productID="+prodid;

Answer Source

Instead of HTTP_REFERRER you can use location.reload() after deleting a item to refresh the changed contents. Below is the example:

function deleteproduct(prod) { 
    if(confirm('Are you sure you want to delete this product')) { 

        $.get( "del_product.php", { act: "del", 
                                    masterCategory: "<?php echo $parent; ?>", 
                                    subCategory: "<?php echo $child; ?>",
                                    pro‌​ductID: prodid } )
            .done(function( data ) {
                alert( "Data Loaded: " + data );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download