2012-02-22 86 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>