ASP.NET MVC 学习心得 (5) –AJAX

  1. 添加视图

    <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>

     

  2. 添加控制器

    public ActionResult HelloJason()

     {

    return this.Json("From server");

}

posted @ 2009-04-21 10:51  许晓光  阅读(198)  评论(0编辑  收藏  举报