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

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝