2012-02-22 94 views
1

我正在使用c sharp语言在asp.net上工作。我想在下拉菜单上使用ajax。当用户从下拉菜单中选择一个项目时,相关信息必须显示给用户。在asp.net中调用Ajax的步骤

请告诉我在这种情况下使用ajax的步骤。

感谢

回答

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>