2 回答

TA貢獻1829條經(jīng)驗 獲得超7個贊
我最終做的并不是一個完美的方法。但它解決了我的問題。所以我正在分享它。我歡迎針對此問題的所有建議和任何其他解決方案。
switch dbStatus {
case 0://db Error
dataToClient = "Server Connection Error"
this.Ctx.ResponseWriter.Write([]byte(dataToClient)) //Error_msg_1
case 1://Email already in use
dataToClient = "EmailError"
this.Ctx.ResponseWriter.Write([]byte(dataToClient)) //Error_msg_2
case 2://UserName already in use
dataToClient = "UserNameError"
this.Ctx.ResponseWriter.Write([]byte(dataToClient)) //Error_msg_3
case 3://Everything is fine
if user.UserType == 0 { //Choosing the url
dataToClient = "/admin_home" //url_1
this.Ctx.ResponseWriter.Write([]byte(dataToClient))
} else {
dataToClient = "/user_home" //url_2
this.Ctx.ResponseWriter.Write([]byte(dataToClient))
}
}
我沒有成功找到從后端重定向的方法。所以我編碼從后端選擇url路徑并將其發(fā)送到前端this.Ctx.ResponseWriter.Write([]byte(dataToClient))
現(xiàn)在在前端我做了以下事情:
$("#signupForm").validate({
rules: {
fullName: "required"
},
messages: {
fullName: "Please enter your full name"
},
submitHandler: function(form){
$(form).ajaxSubmit({
url: '/add_user',
type: 'POST',
dataType: 'html',
data : $( "#signupForm" ).serialize(),
success : function(data) {
//Checking whether the data from back-end is an url or not...
if (data.charAt(0) === '/'){ // if url
window.location.href = data;
}else{ //else error message
document.getElementById('regError').innerHTML = data;
}
}
});
return false
}
});
});

TA貢獻1875條經(jīng)驗 獲得超5個贊
你不能用 c.Redirect(redirectURL, 302) 重定向到一個全新的控制器,其中 'c' 是你的控制器嗎?
我基本上對“/”、“/register”等使用不同的控制器。
- 2 回答
- 0 關(guān)注
- 127 瀏覽
添加回答
舉報