zoukankan      html  css  js  c++  java
  • 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 %}
    
  • 相关阅读:
    百度之星资格赛1001——找规律——大搬家
    HDU1025——LIS——Constructing Roads In JGShining's Kingdom
    DP(递归打印路径) UVA 662 Fast Food
    递推DP UVA 607 Scheduling Lectures
    递推DP UVA 590 Always on the run
    递推DP UVA 473 Raucous Rockers
    博弈 HDOJ 4371 Alice and Bob
    DFS(深度) hihoCoder挑战赛14 B 赛车
    Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)
    DP(DAG) UVA 437 The Tower of Babylon
  • 原文地址:https://www.cnblogs.com/yblackd/p/13162703.html
Copyright © 2011-2022 走看看