weixin_33749131 2013-06-06 12:18 采纳率: 0%
浏览 189

Ajax调用和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;
        });
    });
  • 写回答

1条回答 默认 最新

  • weixin_33749131 2013-06-06 12:26
    关注

    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";  
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!