zoukankan      html  css  js  c++  java
  • 微软自带的异步Ajax请求

    一、使用步骤

    二、示例代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace WebApplication3.Controllers
    {
        public class MSAjaxController : Controller
        {
            // GET: MSAjax
            public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult GetPrices(int id)
            {
                string result = (id*10)+"";
                System.Threading.Thread.Sleep(2000);
    
                return Content(result);
            }
        }
    }
    View Code
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
        <script src="~/Scripts/jquery-1.10.2.min.js"></script>
        <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
        <script type="text/javascript">
            function success(data) {
                //alert(data);
            };
        </script>
    </head>
    <body>
        <div> 
            @using (Ajax.BeginForm("GetPrices", "MSAjax", new AjaxOptions()
            {
                Confirm = "确定获取吗?",
                HttpMethod = "POST",
                InsertionMode = InsertionMode.Replace,
                LoadingElementId = "loadingImg",
                UpdateTargetId = "lblPrice",
                OnSuccess = "success"
            }))
            {
                <div>
                    请输入Id号:<input type="text" name="id" /><br />
                    <input type="submit" value="获取价格" /><br />
                    价格:<label id="lblPrice"></label>
                    <div id="loadingImg" style="display:none">
                        <img src="~/Content/ico_loading.gif" />
                    </div>
                </div>
            }
        </div>
    </body>
    </html>
    View Code
  • 相关阅读:
    JAVA设计模式之桥接模式
    Pycharm新建模板默认添加作者时间等信息
    Handler机制(2)转载
    内部类学习
    设计模式-1依赖倒置原则示例
    正则表达式
    Service原理及例子
    Serializable接口
    设计模式之静态工厂模式
    Handler机制post方法使用
  • 原文地址:https://www.cnblogs.com/shaomenghao/p/4020236.html
Copyright © 2011-2022 走看看