无法在Parse.com上保存课程

时间:2016-01-02 17:23:30

标签: javascript jquery parse-platform

为什么这段代码不允许我将我的用户类从我的网站保存到parse.com?

当我在提交函数之外运行此代码时,它工作正常,当我在提交函数中运行它时,我得到警告:“检查”但从不“保存”。所以出于某种原因,在这个函数内部.save()不起作用。如果有帮助的话,我在Ruby On Rails上运行它。

Parse.initialize("xxxxx", "xxxxx");

$(document).ready(function() {
  $("#new_user").submit(function() {     

    var User = Parse.Object.extend("_User");     
    var user = new User();      

    user.set("name","john doe");
    user.set("username","fff29@test.edu");
    user.set("email","fff29@test.edu");
    user.set("password","password123");

    alert("check");
    user.save();  
    alert("save");
  });

});

我将代码更改为此但仍然无效:

Parse.initialize("xxxxx", "xxxx");

$(document).ready(function() {
  $("#new_user").submit(function() {          
        var user = new Parse.User();
        user.set("username", "my name");
        user.set("password", "my pass");
        user.set("email", "email@example.com");

        user.signUp(null, {
          success: function(user) {
            // Hooray! Let them use the app now.
          },
          error: function(user, error) {
            // Show the error message somewhere and let the user try again.
            alert("Error: " + error.code + " " + error.message);
          }
        });
  });

});

这是从解析网站上复制并粘贴的,因此我的网页一定有问题,而不是我猜的解析代码。这是我对注册页面的看法:

<!DOCTYPE html>
<html>

    <head>
        <% content_for :title, "Join Dot" %>
        <%= javascript_include_tag "user-bundle" %>
        <script src="//www.parsecdn.com/js/parse-1.6.12.min.js"></script>
    </head>

    <div class="title">
      <p>Sign Up</p>
    </div>

    <%= form_for @user do |f| %>
      <%= f.text_field :name, :placeholder => "Full Name", :id => "name" %>
      <%= f.email_field :username, :placeholder => "Email", :id => "username" %>
      <%= f.password_field :password, :placeholder => "Password", :id => "password"%>
      <%= f.submit "Join", class: "btn-submit" %>
    <% end %>

</html>

1 个答案:

答案 0 :(得分:2)

逐步完成整个过程。退出&#39;用户&#39;保存之前,确保它是一个有效的解析类。您可能需要将Parse.Object.extend("_User")更改为new Parse.User(),将user.save()更改为user.signUp()