一.普通的异步请求

1.View层

<input type="text" id="Name" value="" placeholder="请输入账号" />
    <input type="password" id="Password" value="" placeholder="请输入密码" />
    <input type="button" id="btn" value="提交 " />

 

2.controller层

public ActionResult Index()
        {
            
            return View();
        }
        public string JqueryPost()
        {
            string Name = Request["Name"].ToString();
            string Pwd = Request["Password"].ToString();
            return "Name:" + Name + "Pwd:" + Pwd;
        }

 

3.JS

<script src="~/Content/js/jquery-2.2.4.min.js"></script>
<script>
    $(function () {
        $('#btn').click(function () {//点击提交按钮触发点击事件
            $.post(
     "/Headquarter/JqueryPost",//请求的控制器方法(url)
     {
         Name: $('#Name').val(),     
         Password: $('#Password').val()
     },//发送数据到控制器,键值对形式 (data)
     function (data) {//获取控制器传过来的数据(回调函数)
         layer.alert(data);
     })
        });
    });
</script>

4.运行

MVC异步加载学习笔记

MVC异步加载学习笔记

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-09-30
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-10-23
  • 2021-12-07
  • 2021-05-22
  • 2021-09-21
相关资源
相似解决方案