我想通过使用ajax函数显示下拉列表的选定索引的值。这是行不通的。我尝试使用控制台调试它,我看到了错误500 (Internal Server Error)
是什么导致了这个问题?实施如下
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:
<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>
网络方法:
[System.Web.Services.WebMethod]
private String getData(String color)
{
return "Hello " + color;
}
答案 0 :(得分:0)
将webmethod的访问说明符更改为public
。我们将其设置为private
答案 1 :(得分:0)
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方法
[System.Web.Services.WebMethod]
public String getData(String color)
{
return "Hello " + color;
}
试试这个