使用Parse Javascript SDK注册用户

时间:2015-07-21 01:16:57

标签: javascript parse-platform registration

以下是我的表单模板,它加载在我的register.html页面的标题中,并显示在div#register-tpl中。它显示很好。系统会提示用户注册用户名,电子邮件和密码:

<script id="register-tpl" type="text/x-handlebars-template">
    <form class="form-register" role="form">
        <h1>Sign up!</h1>
        <h2><span class="typcn typcn-user-add"></span>&nbsp;Create an account</h2>
        <p><input type="text" id="username" name="username" class="form-control" placeholder="Username" required="" autofocus=""></p>
        <p><input type="password" id="password" name="password" class="form-control" placeholder="Password" required=""></p>
        <p><input type="text" id="email" name="email" class="form-control" placeholder="Email" required="" autofocus=""></p>
        <p><button class="button" type="submit">Sign up</button></p>
        <p>Already have an account? <a class="app-link" href="admin.html">Log in!</a></p>
    </form>
</script>

以下是我将新用户添加到数据库的Javascript代码:

                var RegisterView = Parse.View.extend({
                template: Handlebars.compile($('#register-tpl').html()),
                events: {
                    'submit .form-register': 'register'
                },
                register: function(e) {

                    e.preventDefault();

                    var username = document.getElementById('username').value;     
                    var password = document.getElementById('password').value;
                    var email = document.getElementById('input').value;

                    var user = new Parse.User();
                    user.set("username", username);
                    user.set("password", password);
                    user.set("email", email);

                    user.signUp(username, password, email, {

                        success: function(user) {
                            var welcomeView = new WelcomeView({ model: user });
                            welcomeView.render();
                            $('.register-container').html(welcomeView.el);
                        },

                        error: function(user, error) {
                            console.log(error);
                        }
                    });
                },
                render: function(){
                    this.$el.html(this.template());
                }
            });

有没有人知道为什么没有提交所需的信息?它甚至没有认识到在Parse仪表板上创建新用户。这里存在根本缺陷吗?谢谢,非常感谢所有帮助!

1 个答案:

答案 0 :(得分:0)

解决方案涉及指定要在成功回调中提交的表单:document.getElementById(&#34; user-add&#34;)。submit()。设置字段变量时,我也遇到了常见的拼写错误。它应该读取var username = form.username.value;而不是username = document.username.value;!

$("#table1 input[type=checkbox]").on('click', function ()
{
    $(this).parent().parent().toggleClass('highlight');
});

$("#table2 input[type=checkbox]").on('click', function ()
{
    $(this).parent().toggleClass('highlight');
});