[英]ASP.NET Response Redirect of URL Error; from static method
我正在使用ASP.NET 3.5 App。 我有$ ajax jQuery函數調用帶有發送人員ID的代碼隱藏方法。
我想從此方法打開Response.Redirect但出現以下錯誤
$.ajax({
url: 'AddUserInRole.aspx/GetRolesListFilteredByStaff_NotIn',
type: "POST",
data: JSON.stringify({ GivenStaffID: selectStaffIDToAddRole }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
},
failure: function (response) {
alert(response.d);
}
}).done(function (response) {
//
});
[WebMethod]
private static void GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
{
Response.Redirect("/SelectRoleForStaff.aspx?staffID='GivenStaffID'");
}
我的第二個問題是如何從新上傳頁面的網址中讀取staffID
我設法調用了require方法,但未重定向頁面...
[WebMethod]
public static void GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
{
HttpContext.Current.Response.Redirect("/SelectRoleForStaff.aspx?staffID="+GivenStaffID);
}
更新您的方法以返回要重定向的網址,例如:
[WebMethod]
public static string GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
{
return "SelectRoleForStaff.aspx?staffID=" + GivenStaffID;
}
為了使您的ajax成功,請執行以下操作:
success: function (response) {
window.location = response;
// OR
window.location = response.d;
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.