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
  • 相关阅读:
    ES基本原理
    docker技术基础
    docker简介
    IaaS,PaaS和SaaS
    python的type和object
    django:一个RESTfull的接口从wsgi到函数的历程
    python的list内存分配算法
    10个我最喜欢问程序员的面试问题
    月薪三万的面试题
    深圳有趣网络笔试题面试题
  • 原文地址:https://www.cnblogs.com/shaomenghao/p/4020236.html
Copyright © 2011-2022 走看看