简体   繁体   English

ASP:.NET Ajax函数在onchange事件后不起作用

[英]ASP:NET ajax function does not work after onchange event

I want to show the value of the selected index of a dropdownlist by using an ajax function. 我想通过使用ajax函数显示下拉列表的选定索引的值。 It does not work. 这是行不通的。 I try to debug it by using the console and i saw that error 500 (Internal Server Error) What is causing that problem ? 我尝试使用控制台进行调试,但看到该错误500 (Internal Server Error)是什么原因引起的? The implementation is below 实现如下

Ajax functions: Ajax函数:

        function showDdlValue(ddl) {
        var value = ddl.value;
        $.ajax({
            type: "POST",
            url: "AdminPanel.aspx/getData",
            data: '{color: "' + value + '" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            failure: function (response) {
                alert(response.d);
            }
        });
    }

    function OnSuccess(response) {
        alert(response.d);
    }

Html: HTML:

                <ajaxToolkit:TabPanel ID="TabPanel5" runat="server">
                <HeaderTemplate>Show Shoes</HeaderTemplate>
                <ContentTemplate runat="server">                                                               
                    <asp:Repeater ID="shoeRepeater" OnItemDataBound="shoeRepeater_ItemDataBound" runat="server">
                        <HeaderTemplate></HeaderTemplate>
                        <ItemTemplate>
                            <table border="1" style="border-color:#ff9900; width:400px; font-weight:bold; font-family:'Oswald', Arial, sans-serif;">
                                <tr>
                                    <td rowspan="6" style="width:150px; height:150px;">
                                        <image src="shoeImages/<%#DataBinder.Eval(Container.DataItem,"ImagePath") %>"></image>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <%#DataBinder.Eval(Container.DataItem,"BrandName") %> <%#DataBinder.Eval(Container.DataItem,"ModelName") %> 
                                    </td>

                                </tr>
                                <tr>
                                    <td>
                                        Price: $<%#DataBinder.Eval(Container.DataItem,"Price") %>
                                    </td>

                                </tr>
                                <tr>
                                    <td>
                                        Size: <%#DataBinder.Eval(Container.DataItem,"Size") %>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Color:<asp:DropDownList ID="colorList1" onchange="showDdlValue(this)" runat="server">
                                        </asp:DropDownList>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Quantity: <%#DataBinder.Eval(Container.DataItem,"Quantity") %>
                                    </td>

                                </tr>
                            </table>
                        </ItemTemplate>
                        <FooterTemplate></FooterTemplate>
                    </asp:Repeater>
                </ContentTemplate>
            </ajaxToolkit:TabPanel>

Web method: 网络方法:

    [System.Web.Services.WebMethod]
    private String getData(String color) 
    {
        return "Hello " + color;
    }

Change the access specifier of the webmethod to public . 将web方法的访问说明更改为public It is not accessible when we set it as private 当我们将其设置为private时将无法访问

function showDdlValue(ddl) {
    var value = ddl.value;
    $.ajax({
        type: "POST",
        url: "AdminPanel.aspx/getData",
        data: {'color':  value },
        success: OnSuccess,
        failure: function (response) {
            alert(response);
        }
    });
}

function OnSuccess(response) {
    alert(response);
}

WEB METHOD 网页方式

[System.Web.Services.WebMethod]
public String getData(String color) 
{
    return "Hello " + color;
}

Try this 尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM