Szabi Zsoldos
Szabi Zsoldos

Reputation: 351

ajax call and window.location

I'm working on a shopping cart and I'm having some difficulties with a concept. Basicly, I remove two articles in a certain condition and it works perfectly.

My problem is that I want to redirect the user instantly if these two articles are removed from the cart. When I enter the window.location, it is refreshing the page but it's not updating the cart from the ajax call.

So what I want to achieve is that after these two ajax calls, i want to be redirected but also, the ajax call should do their things in the delete_item.php :) I'm using jQuery inside a normal javascript file on a certain function.

function deleted(id, pozitie) {
    var msg = 0;
    $(document).ready(function(){                    
        $('.' + id).each(function() { 
            $(this).remove();
            $('.sm').remove();
            ajaxpage("delete_item.php?id="+pozitie+"&ord="+ordrno,"error");
            ajaxpage("delete_item.php?id="+(pozitie+1)+"&ord="+ordrno,"error");
            window.location="http://mypage.com/offer";
            msg = 1;
        });
    });

Upvotes: 0

Views: 1471

Answers (1)

Sudip
Sudip

Reputation: 2051

Use a callback function and redirect your page if your ajax call return success. Hope it works.

ajaxpage("delete_item.php?id="+pozitie+"&ord="+ordrno,"error",callbackfn);

Callback funfction:

function callbackfn(){  
window.location="http://mypage.com/offer";  
}

Upvotes: 1

Related Questions