• ajax提交数据


    html代码

    1 <input class="form-control" id="username" name="username" type="text"/>
    2 <input class="form-control" id="password" name="password" type="password"/>
    3 
    4 <button type="button" onclick="loginSubmit()">立即登录</button>

    jquery代码

    function loginSubmit() {
    
            var username = $("#username").val();    // 获取id为username的<input>框数据
            var password = $("#password").val();    // 获取id为password的<input>框数据
            // 判断
            if (username.length == 0) {
                $("#username").tips({msg: "请输入用户名。"});
                return;
            }
            if (password.length == 0) {
                $("#password").tips({msg: "请输入密码。"});
                return;
            }
            // Ajax提交数据
            $.ajax({
                url: "admin/check_login",    // 提交到controller的url路径
                type: "post",    // 提交方式
                data: {"username": username, "password": password},  // data为String类型,必须为 Key/Value 格式。
                dataType: "json",    // 服务器端返回的数据类型
                success: function (data) {    // 请求成功后的回调函数,其中的参数data为controller返回的map,也就是说,@ResponseBody将返回的map转化为JSON格式的数据,然后通过data这个参数取JSON数据中的值
                    if (data.message == "success") {    
                        //跳转到系统首页
                       ......
                    } else {
                        ......
                    }
                },
            });
        }

    Ajax中success回调函数: 
    success: function(data)是Ajax在请求成功后自动调用的,所以这个方法是Ajax调用的,那么该方法的参数(data)便是Ajax提供的了。其中function(data)的参数data是客户端请求后台,由后台返回的值。

  • 相关阅读:
    systemtap分析软raid io拆分问题
    Profiling Java Application with Systemtap
    中国南方ORACLE用户组
    Docker 核心技术与实现原理
    The Internals of PostgreSQL
    Alone_Monkey 逆向IOS
    淘宝内核月报 2017
    Linux kernel engineer--trace
    你的按钮到底在帮助用户还是在误导用户?
    2020年值得你去试试的10个React开发工具
  • 原文地址:https://www.cnblogs.com/lihuibin/p/9546373.html
Copyright © 2020-2023  润新知