@using (Ajax.BeginForm("GetTime","order",new AjaxOptions() { Confirm="你确认这么做吗?", HttpMethod="post", OnSuccess = "afterajax", UpdateTargetId="result", InsertionMode=InsertionMode.Replace, LoadingElementId = "loading", })) { <input type="text" name="txtname" /> <input type="submit" name="获取时间" /> } <div id="loading"> <img src="~/Content/Images/loading.gif" /> </div> <div id="result"> </div>
Html部分代码
<script src="~/Scripts/jquery-1.8.2.js"></script> <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script> <script type="text/javascript"> $(function () { $("#loading").css("display", "none"); $("#btnGetTime").click(function () { $.ajax({ url: "/order/GetTime", data: {}, type: "post", success: function (data) { alert(data); } }); $.get("/order/GetTime", {}, function (data) { alert(data); }); } ) }); function afterajax(data) { alert("ff"); } function aff() { $("#loading").css("display", "none"); } </script>