生活随笔
收集整理的這篇文章主要介紹了
Ajax提交后Moedl And View不进行页面跳转的解决方案
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
場(chǎng)景
前端使用ajax請(qǐng)求后臺(tái),返回Model And View 后不進(jìn)行頁(yè)面跳轉(zhuǎn)。
用ajax提交是沒(méi)有頁(yè)面跳轉(zhuǎn)的。
實(shí)現(xiàn)
如果只是簡(jiǎn)單的頁(yè)面跳轉(zhuǎn)和傳遞單個(gè)簡(jiǎn)單參數(shù)可以使用:
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) {debuggerif("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){//請(qǐng)求失敗處理函數(shù)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");//將聯(lián)系人信息存儲(chǔ)到cookie中if(contactCookie && contactCookie!=""){//查看是否是當(dāng)前登錄用戶的填寫信息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", //彈窗內(nèi)容的布局position: "middle", //位置類型(top,bottom,left,right,middle)effectIn: "bounceInDown", //彈窗顯示效果effectOut: "bounceOutDown", //彈窗消失效果maskPosition:"11", //Mask的z-index數(shù)值closeBtn: ".login_dialog_plugin_close" //關(guān)閉彈窗按鈕})}}},error : function(err) {$("#book > button:submit").removeAttr("disabled","disabled").text("下一步,去支付");$('#clause').removeAttr("disabled","disabled");//請(qǐng)求失敗處理函數(shù)webToast("請(qǐng)求錯(cuò)誤", "middle", "mask", 1000);}});}return false;});
?
總結(jié)
以上是生活随笔為你收集整理的Ajax提交后Moedl And View不进行页面跳转的解决方案的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。