ASP.NET MVC 学习心得 (5) –AJAX
- 添加视图
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script language="javascript" type="text/javascript" src="/Scripts/jquery-1.2.6.min.js"></script>
<script language="javascript" type="text/javascript">
function HelloJquery()
{
$.ajax(
{
url: "HelloJason",
type:"POST",
datatype : "json",
timeout : 1000,
success: GetResult
}
);
}
function GetResult(result)
{
alert(result.toString());
}
</script>
<h2>Async</h2>
<input type="button" value="Get Server Data" onclick="HelloJquery()" />
</asp:Content>
- 添加控制器
public ActionResult HelloJason()
{
return this.Json("From server");
}