简体   繁体   English

Ajax调用和window.location

[英]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. 当我进入window.location时,它正在刷新页面,但没有从ajax调用中更新购物车。

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. 所以我想实现的是,在这两个ajax调用之后,我想被重定向,而且,ajax调用也应该在delete_item.php中完成它们的工作:)我在某个功能的普通javascript文件中使用jQuery 。

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;
        });
    });

Use a callback function and redirect your page if your ajax call return success. 如果您的ajax调用返回成功,请使用callback函数并重定向页面。 Hope it works. 希望它能工作。

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

Callback funfction: 回调函数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM