我正在使用c语言在asp.net上工作。我想在下拉菜单上使用ajax。当用户从下拉列表中选择项目时,必须向用户显示相关信息。
请告诉我在这种情况下使用ajax的步骤。
由于
答案 0 :(得分:0)
所以假设你有一个下拉列表
<select id='drId'>...</select>
以及将返回信息的操作
public ActionResult ShowInfo(int v)
{
// return info about object with key = v
return Content("hi");
}
此脚本将处理下拉列表的更改客户端事件
<script>
$(function(){
$('#drId').change(function(){
$.post('<%=Url.Action("ShowInfo")%>',{ v:$(this).val() },function(result){
//do something with result;
alert(result);
});//end post
});//end change
});//end doc ready
//don't forget to include jQuery
</script>