Ajax提交后Moedl And View不进行页面跳转的解决方案

场景

前端使用ajax请求后台,返回Model And View 后不进行页面跳转。

用ajax提交是没有页面跳转的。

实现

如果只是简单的页面跳转和传递单个简单参数可以使用:

window.location.href = "${ctx}/frontPage/passFlight/GJbookPay.html?orderId="+data.result;

完整示例代码:


 

$("#book").submit(function() {
  if($(this).Andrew_Validate("submit_Validate")){
   $("#book > button:submit").attr("disabled","disabled").text("订单提交中...");
   $('#clause').attr("disabled","disabled");
   var actionurl = $(this).attr("action"); //提交路径
   var data = $(this).serialize();
   console.log(data);
   $.ajax({
    async : true,
    cache : false,
    type : 'POST',
    url : actionurl,
    data : data,
    success : function(data) {
     debugger
     if("200"==data.statusCode){
      
      window.location.href = "${ctx}/frontPage/passFlight/GJbookPay.html?orderId="+data.result;
     }
     if("300"==data.statusCode){
      $("#book > button:submit").removeAttr("disabled","disabled").text("下一步,去支付");
      $('#clause').removeAttr("disabled","disabled");
       if(-1==data.result){
       //请求失败处理函数
       webToast(data.message, "middle", "mask", 1000);
       }else{
        var contactName=$("#contactName").val();
        var contactAreaCode=$("#contactAreaCode").val();
        var contactAreaMobile=$("#contactAreaMobile").val();
        var email=$("#email").val();
        var phone=$("#phone").val();
        var contactCookie = $.cookie("bus__contact");
        //将联系人信息存储到cookie中
        if(contactCookie && contactCookie!=""){
             //查看是否是当前登录用户的填写信息
             contactCookies=contactCookie.split(";"); //字符分割
             var tempCookie;
             for(j = 0; j < contactCookies.length; j++) { 
             tempCookie=contactCookies[j].split(",");
              if(tempCookie[4]==phone){
               var s=contactName+','+contactAreaCode+','+contactAreaMobile+','+email+','+phone;
               contactCookies.splice(j,1,s);
               $.cookie('bus__contact',contactCookies);
             }
              else{
             var contactResult=contactCookie+";"+contactName+','+contactAreaCode+','+contactAreaMobile+','+email+','+phone;
             $.cookie('bus__contact',contactResult);
              }
              }
            }
          else{
          var contactResult=contactName+','+contactAreaCode+','+contactAreaMobile+','+email+','+phone;
          $.cookie('bus__contact',contactResult);
          }
         Andrew_Popupwin({
                  dom: "#login_dialog_plug_popupWin", //弹窗内容的布局
                  position: "middle", //位置类型(top,bottom,left,right,middle)
                  effectIn: "bounceInDown", //弹窗显示效果
                  effectOut: "bounceOutDown", //弹窗消失效果
                  maskPosition:"11", //Mask的z-index数值
                  closeBtn: ".login_dialog_plugin_close" //关闭弹窗按钮
              })
       }
     }
    },
    error : function(err) {
     $("#book > button:submit").removeAttr("disabled","disabled").text("下一步,去支付");
     $('#clause').removeAttr("disabled","disabled");
     //请求失败处理函数
     webToast("请求错误", "middle", "mask", 1000);
    }
   });
  }
  return false;
 });



 

你可能感兴趣的:(SSM)