简体   繁体   中英

Can't save class on Parse.com

Why doesn't this code allow me to save my user class from my website to parse.com?

When I run this code outside of the submit function it works fine and when I run it inside of the submit function, I get to the alert: "check" but never to "save". So for some reason inside of this function .save() does not work. I'm running this on Ruby On Rails if that helps.

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");
  });

});

I changed my code to this but it's still not working:

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);
          }
        });
  });

});

This is copied and pasted off the parse website so it must be something wrong with my webpage and not my parse code i'm guessing. Here's my view for the sign up page:

<!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>

Step through the process. Log out 'user' before saving and make sure it's a valid parse class. You may need to change Parse.Object.extend("_User") to new Parse.User() and user.save() to user.signUp() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM