C# 无法将方法从ajax方法重定向到aspx.cs页面
我的CenterDetail.aspx页面中有以下代码C# 无法将方法从ajax方法重定向到aspx.cs页面,c#,css,asp.net,ajax,C#,Css,Asp.net,Ajax,我的CenterDetail.aspx页面中有以下代码 function myFunction(id) { console.log(2); var myindex = window.ContentPlaceHolder1_ddCountryId.selectedIndex; console.log(myindex); var selectedName = window.ContentPlaceHolder1_ddCountryId.options[myindex]
function myFunction(id) {
console.log(2);
var myindex = window.ContentPlaceHolder1_ddCountryId.selectedIndex;
console.log(myindex);
var selectedName = window.ContentPlaceHolder1_ddCountryId.options[myindex].text;
console.log(selectedName);
var loc = window.location.href;
console.log(loc);
$.ajax({
type: "POST",
url: loc + "/BindState",
data: { id : id },
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data);
}
});
}
下面的方法在我的代码隐藏文件中
[WebMethod]
public static string BindState(int id)
{
var states = new StateProvinceCollection().Where(StateProvince.Columns.CountryId = Convert.ToString(id), true).ToList();
string tag = "<select id='StateProvinceId' name='StateProvinceName'>";
tag += "<option value=''>select</option>";
foreach (var item in states)
{
tag += "<option value='" + item.StateProvinceId + "'>" + item.StateProvinceName + "</option>";
}
tag += "</select>";
return tag;
}
一切仍然是它显示404未找到错误 你想转往哪里?我的意思是你有要重定向的URL吗?**URL:loc+/BindState,**这是我的URL为什么要重定向到该URL?该URL用于WebMethod,而不是aspx页面。您只能重定向到aspx页面或类似abc.aspx或abc.html或abc.htm的html页面。我想从上面编写的方法中获取数据。。所以我编写了一个ajax方法,在其中可以看到url部分,方法BindState在我的代码隐藏文件中。ajax被调用,但在ajax中它会在url部分停止。通过显示以下错误:404未找到错误。