• 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 %}
  • 相关阅读:
    Highcharts之饼图
    设计模式学习之原型模式
    jQuery学习之结构解析
    JS学习之闭包的理解
    JS学习之prototype属性
    JS学习之事件冒泡
    Mybatis学习之JDBC缺陷
    Spring学习之Aop的基本概念
    Struts学习之值栈的理解
    Struts学习之自定义结果集
  • 原文地址:https://www.cnblogs.com/yblackd/p/14533392.html
Copyright © 2020-2023  润新知