简体   繁体   English

使用parse进行注册的用户可以使用断点,但如果没有

[英]Sign up user using parse works with breakpoint, fails without

I have a signup form with the fields Firstname, lastname, email, class of, and college major and I am trying to send the information from the form to a parse user object. 我有一个注册表单,其中包含“名字”,“姓氏”,“电子邮件”,“课程类别”和“大学专业”字段,我正在尝试将信息从表单发送到解析用户对象。 When I set a breakpoint at "user.signup" the code steps through and I see the new user show up in my parse dashboard. 当我在“ user.signup”处设置断点时,代码会逐步执行,并且我会在解析仪表板上看到新用户。 However, if I remove the breakpoint and submit the form I get the error: 但是,如果我删除断点并提交表单,则会收到错误消息:

"Error: 100 XMLHttpRequest failed: {"statusText":"","status":0,"response":"","responseType":"","responseXML":null,"responseText":"","upload":{"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null},"withCredentials":false,"readyState":4,"timeout":0,"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null}" “错误:100 XMLHttpRequest失败:{“ statusText”:“”,“ status”:0,“ response”:“”,“ responseType”:“”,“ responseXML”:null,“ responseText”:“”,“上传“:{” ontimeout“:null,” onprogress“:null,” onloadstart“:null,” onloadend“:null,” onload“:null,” onerror“:null,” onabort“:null},” withCredentials“: false,“ readyState”:4,“超时”:0,“ ontimeout”:null,“ onprogress”:null,“ onloadstart”:null,“ onloadend”:null,“ onload”:null,“ onerror”:null, “ onabort”:null}“

the code for my javascript file is: 我的javascript文件的代码是:

function SignUp() {
var user = new Parse.User();
var form = document.getElementById("signup-form")

var firstname = form.firstname.value;
var lastname = form.lastname.value;
var email = form.email.value;
var grad = form.grad.value;
var major = form.major.value;
var password = "6789";

user.set("firstname", firstname);
user.set("lastname", lastname);
user.set("email", email);
user.set("username", email);
user.set("grad", grad);
user.set("major", major);
    user.set("password", password);


user.signUp(null, {
  success: function(user) {
    // Hooray! Let them use the app now.
    alert("Thank you for signing up. We'll keep you updated!");
  },
  error: function(user, error) {
    // Show the error message somewhere and let the user try again.
    alert("Error: " + error.code + " " + error.message);
  }

});

return false;

}; };

In my html file I am calling this function at: 在我的html文件中,我在以下位置调用此函数:

<form class="form-signup" role="form" id="signup-form" onsubmit="SignUp();">

Is there an issue with how I'm storing the values? 我如何存储值是否存在问题? I don't understand how something can work with a breakpoint but not without. 我不明白某些事情如何与断点一起工作,但并非没有断点。 Any help is really appreciated! 任何帮助都非常感谢!

That's the typical problem with returning a value from within an asynchronous method … which is not possible. 这是从异步方法中返回值的典型问题……这是不可能的。

Prevent the default submitting of the form, and then submit it explicitly within the call back function. 阻止默认提交表单,然后在回调函数中显式提交表单。

There is an another way also to solve this problem: 还有另一种方法可以解决此问题:

Instead of form in form class="form-signup" role="form" id="signup-form" onsubmit="SignUp()" 代替form class="form-signup" role="form" id="signup-form" onsubmit="SignUp()"

Write div ie div class="form-signup" role="form" id="signup-form" onsubmit="SignUp()" 写div即div class="form-signup" role="form" id="signup-form" onsubmit="SignUp()"

As stated above, just add e.preventDefault(); 如上所述,只需添加e.preventDefault();即可。 at the start of your function and document.getElementById("your-form-id").submit(); 函数document.getElementById(“ your-form-id”)。submit();开头 or in this case just form.submit(); 或者在这种情况下只是form.submit(); (because it was defined earlier in the script by var form ) into the success callback and it should work! (因为它是在脚本前面由var form定义的)进入成功回调 ,它应该可以工作! Thought I would add a bit of clarity to reinforce CBroe's answer as it wasn't specified what the form.submit function looked like exactly. 我想我会增加一些清晰度,以加强CBroe的答案,因为它没有指定form.submit函数的确切外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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