一个多星期以来,我问了一个关于Jquery 和 Ajax的问题。我仍然不知道如何利用答案,因为我对此事还有更多问题。这是我的aspx页面。
<asp:ListView ID="_lsvCostFinder" runat="server" InsertItemPosition = "LastItem">
<LayoutTemplate>
<table>
<tr>
<th>Country</th>
<th>City</th>
<th>Cost(US$)</th>
</tr>
<tr runat="server" id="itemPlaceHolder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="_lnkDelete" runat="server" OnClick = "RemoveDestination">Delete</asp:LinkButton>
</td>
<td>
<asp:DropDownList ID="_ddlCountry" runat="server" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" AutoPostBack = "true">
<asp:ListItem Value = "0">CANCEL..</asp:ListItem>
<asp:ListItem Value = "1">USA</asp:ListItem>
<asp:ListItem Value = "2">Germany</asp:ListItem>
<asp:ListItem Value = "3">France</asp:ListItem>
<asp:ListItem Value = "4">GB</asp:ListItem>
<asp:ListItem Value = "5">Congo</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="_ddlCity" runat="server" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged" AutoPostBack = "true"
AppendDataBoundItems = "true" Width = "100">
<asp:ListItem Value = "0">CANCEL..</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="_txtCost" runat="server" Width = "50" AutoPostBack = "true" OnTextChanged = "txtCost_TextChanged"></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr>
<td style = "text-align: right; font-weight: bold;" colspan = "3">Total</td>
<td style = "background-color: Silver; border: 2px solid black;">
<asp:Label ID="_lblTotal" Font-Bold ="true" runat="server"></asp:Label>
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<br /><br />
<asp:Button ID="_btnNewDestination" runat="server" Text="Add Destination"
onclick="_btnNewDestination_Click" />
回答我问题的人建议我使用以下 JQuery 代码:
$(document).ready(function () {//ready
$('select').change(function () {//select
var id = $(this).attr('id');
if (id.indexOf('_ddlCountry') != -1) {
var nrow = id.match('\\d+');
$.post('Default.aspx/ddlCountry_SelectedIndexChanged', { selectedVal: $(this).val() }, function (data) {
$(this).parents('tr').replaceWith('<tr><td colspan="3"><div>' + $(this).val() + '</div></td></tr>');
});
}
}); //select
});//ready
还要更改签名,使方法看起来像这样
[WebMethod]
public static string MethodName(string selectedVal)
{
return "something";
}
从方法的签名中,我得出结论,Jquery ajax 请求只发送了 1 个参数。我不想只发送 1 个参数。我要发送3,即第一个下拉列表的值,第二个下拉列表的值,文本框的值。
如何通过 ajax 请求发送多个值?
感谢 s 的帮助。