Javascript ASP.NET/C#错误-通过ajax从下拉列表传递值

Javascript ASP.NET/C#错误-通过ajax从下拉列表传递值,javascript,c#,jquery,asp.net,ajax,Javascript,C#,Jquery,Asp.net,Ajax,我试图使用jQueryAjax链接两个下拉列表,但没有得到任何结果 我的下拉列表的ASP.NET代码是: <td><a href="#" title="Choose the park that you would like. Mandatory Field.">Park*</a></td><!-- PARK --> <td> <asp:DropDownList class="form-control" ID="

我试图使用jQueryAjax链接两个下拉列表,但没有得到任何结果

我的下拉列表的ASP.NET代码是:

<td><a href="#" title="Choose the park that you would like. Mandatory Field.">Park*</a></td><!-- PARK -->
<td>
    <asp:DropDownList class="form-control" ID="parkDDL" ClientIDMode="Static" onchange="ShowCurrentBuilding()" style="width:150px;" runat="server">
    <asp:ListItem text="ALL" value="ALL"></asp:ListItem>
    <asp:ListItem text="Central" value="C"></asp:ListItem>
    <asp:ListItem text="West" value="W"></asp:ListItem>
    <asp:ListItem text="East" value="E"></asp:ListItem>
    </asp:DropDownList>
</td>

<td><a href="#" title="Choose the building that you would like">Building</a>     </td><!-- BUILDING -->
<td>
    <asp:DropDownList class="form-control" AutoPostBack="true" ID="buildingDDL" runat="server" style="width:300px;" OnSelectedIndexChanged="buildingToRoom"></asp:DropDownList>
</td>
我只想通过ajax过滤下拉列表,这样页面就不会使用AutoPostBack=“true”重新加载


提前感谢任何能提供帮助的人

使用客户端函数onchange,而不是服务器端OnSelectedIndexChanged。

我很确定OnSelectedChanged是一个特定的服务器端.net事件。如果要执行客户端函数,请尝试onchange.Put onchange而不是OnSelectedChanged。您是否在这个方法中设置了断点:publicstaticarrarylist GetCurrentBuilding(字符串名)?否,我应该设置什么类型的断点?我所指定的函数是我问题的底部。我没有在中添加任何其他内容。谢谢。他在询问服务器端方法中的断点,看看是否达到了。在任何情况下,您是否尝试过onchange?是的,我尝试过,它消除了错误,但如何将其输出到下拉列表中。我正在返回一个数组列表,但我不确定如何在下拉列表中显示它。此外,我甚至不知道如何测试我是否得到了列表,因为我不知道如何输出ArrayList。
function ShowCurrentBuilding() {
$.ajax(
{
type: "POST",
url: "CreateRequest.aspx/GetCurrentBuilding",
data: '{name: ' + $('#<%= parkDDL.ClientID %> option:selected').val() + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}

function OnSuccess(response) {
alert(response.d);
}
$(document).ready(function () {
$('#<%=parkDDL.ClientID %>').on("change",function ShowCurrentBuilding() {
            $.ajax(
            {
                type: "POST",
                url: "CreateRequest.aspx/GetCurrentBuilding",
                data: '{name: "' + $(this).find("option:selected").val() + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccessBuilding,
                failure: function (response) {
                    alert(response.d);
                }
            });
        });

        function OnSuccessBuilding(response) {
            alert(response.d);
        }
namespace Team11
{
  public partial class CreateRequest : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {

//populate my initial drop down lists etc

}
}

//here is the function that is called in the JQuery function

[System.Web.Services.WebMethod]

    public string GetCurrentBuilding(string name)
    {
        string textbx = "";
        textbx = name;

        return textbx;


    }