首页 > 代码库 > mvc ajax请求

mvc ajax请求

@{
ViewBag.Title = "ajax";
}
<script src="http://www.mamicode.com/Scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script src="http://www.mamicode.com/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="http://www.mamicode.com/#" id ="btn" >点击</a>


<h2>ajax</h2>