mvc ajax请求

@{ ViewBag.Title = "ajax"; }

<script src="../../Scripts/jquery-1.4.4.js" type="text/javascript"></script>

<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>

@using (@Html.BeginForm()) { @Ajax.ActionLink("这是一个ajax请求", "ajax", new AjaxOptions

{ UpdateTargetId = "ajaxId", //InsertionMode = InsertionMode.Replace, InsertionMode=InsertionMode.InsertAfter,

HttpMethod = "Post" })

<h2>

</h2>

}

<script type="text/javascript">

    $(function () {

        $("#btn").click(function () {

            $.post("/Home/ajax", function (data, status) {

                if (status == "success") {

                    alert(data.Name);



                }

                else {

                    alert("ajax请求失败");

                }

            })

        });

    });

</script>

<a href="#" id="btn">点击</a>

<h2>

    ajax</h2>

 

你可能感兴趣的:(ajax请求)