HTML 中
<% =Ajax.ActionLink("AJAX调用", "AjaxByJquery", new { name = "tttt" }, new AjaxOptions { LoadingElementId = "Loading", UpdateTargetId = "jqueryResult", InsertionMode = InsertionMode.InsertAfter })%>
显示结果与进度的HTML代码,与上面的代码放在同一个文件中
<div id="loading">loading.......</div>
<div id="result"></div>
<div id="jqueryResult"></div>
如果是jquery,用如下脚本:
js引用
<script src="../../Scripts/jquery-1.3.1-vsdoc.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
Controlls中的代码
public ActionResult AjaxByJquery(String name)
{
ViewData["ajaxHello"] = name;
return View("ajaxContent");
}
ajaxContent.ascx的HTML代码,将控件的代码插入到result标签中,完成结果显示
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% = Html.Encode(ViewData["ajaxHello"]) %>
本文介绍如何利用jQuery库发起AJAX请求,并通过具体的示例代码展示了如何配置请求参数、处理请求成功及失败的情况。此外,还展示了如何在服务器端(C#)处理来自前端的请求并返回数据。
555

被折叠的 条评论
为什么被折叠?



