• form通过ajax以json发送,接受json数据做处理, js获取cookie值


    {% extends "base.html" %}
    
    {% block title %}register{% end %}
    {% block head %}
        <script type="text/javascript" src="{{ static_url('js/jquery-1.12.4.min.js') }}"></script>
    
        <script type="text/javascript">
            function getSteamId(){
    			var c_name = 'steamname';
    			if(document.cookie.length>0){
    			   c_start = document.cookie.indexOf(c_name + "=")
    			   if(c_start!=-1){
    			     c_start=c_start + c_name.length+1
    			     c_end=document.cookie.indexOf(";",c_start)
    			     if(c_end==-1) c_end=document.cookie.length
    			     return unescape(document.cookie.substring(c_start,c_end));
    			   }
    			}
    		}
    
            function register() {
                var username = document.getElementById("user_name").value;
                var password = document.getElementById("pass_word").value;
                var c_password = document.getElementById("c_password").value;
                var mobile = document.getElementById("mobile").value;
                var steam_id = getSteamId()
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: '/user/register',
                    contentType: "application/json",
                    data:JSON.stringify({
                        "username": username,
                        "password": password,
                        "c_password": c_password,
                        "mobile": mobile,
                        "steam_id": steam_id,
                    }),
                    success: function (result) {
                        if (result.code == 200) {
                            window.location.href = "/";
                        }else {
                            alert(result.message)
                        }
                    }
                });
            }
        </script>
    
    
    {% end %}
    
    {% block content %}
        <h1 style="text-align: center">
            {{ data }}
        </h1>
    
        <form>
            <p>用户名:<input type="text" id="user_name" name="username"  placeholder="用户名"></p>
            <p>密码(*):<input type="password" id="pass_word" name="password"  placeholder="密码"></p>
            <p>确认密码(*):<input type="password" id="c_password" name="c_password"  placeholder="确认密码"></p>
            <p>手机号(*):<input type="text" id="mobile" name="mobile"  placeholder="手机号"></p>
            <input type="button" value="注 册"  onclick="register()">
            <a href="/user/login"><input type="button" value="登录"></a>
        </form>
    {% end %}
    
  • 相关阅读:
    Windows10远程桌面连接提示:出现身份验证错误,要求的函数不受支持
    mybatis 中 if-test 判断大坑
    hutool的DateUtil工具类
    SpringBoot启动过程
    数据库事务的隔离级别
    EasyUI管理后台模板(附源码)
    springmvc中自定义拦截器以及拦截器的执行过程
    文件上传(MultipartFile)
    文件下载(使用springmvc框架中ResponseEntity对象)
    json格式实现数据传输
  • 原文地址:https://www.cnblogs.com/yblackd/p/13162703.html
Copyright © 2020-2023  润新知