So I'm using the following JS function for signing up users on a website. It uses Parse. Currently, this function just automatically returns account not created after I fill up info and click on submit. register-submit
is the id of a button. There are no error messages either on the console. I'm very new to javascript and parse and not sure where I'm messing up. Any help will be appreciated!
<script>
$(function(){
event.preventDefault();
$('#register-submit').on('click', function(event) {
Parse.initialize("s1ySDCya6vuDDvFaxKgEGZLxOvdf8pfG4YMtvjcy", "KGJRCBGgvuyfoiqt8hakSJHODu1BeXtqqGNk0Hnl");
var user = new Parse.User();
var form = document.getElementById("register-form")
var usernameVal = form.username.value;
var passwordVal = form.password.value;
var emailVal = form.email.value;
user.set('username',usernameVal);
user.set('password',passwordVal);
user.set('email',emailVal);
user.signUp(null, {
success: function(user) {
form.submit();
alert("Account Successfully Created!");
}, error: function(user,error){
alert("Account Not Created!");
}
});
});
});
</script>
The form is structured like the following:
<form id="register-form" method="post" role="form" style="display: none;">
<div class="form-group">
<input type="text" name="username" id="username" tabindex="1" class="form-control" placeholder="Username" value="">
</div>
<div class="form-group">
<input type="email" name="email" id="email" tabindex="1" class="form-control" placeholder="Email Address" value="">
</div>
<div class="form-group">
<input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<input type="password" name="confirm-password" id="confirm-password" tabindex="2" class="form-control" placeholder="Confirm Password">
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="register-submit" id="register-submit" tabindex="4" class="form-control btn btn-register" value="Register Now">
</div>
</div>
</div>
</form>
can you try this :
<script>
$(function(){
event.preventDefault();
$('#register-form').submit(function(event) {
Parse.initialize("s1ySDCya6vuDDvFaxKgEGZLxOvdf8pfG4YMtvjcy", "KGJRCBGgvuyfoiqt8hakSJHODu1BeXtqqGNk0Hnl");
var user = new Parse.User();
var form = document.getElementById("register-form")
var usernameVal = form.username.value;
var passwordVal = form.password.value;
var emailVal = form.email.value;
user.set('username',usernameVal);
user.set('password',passwordVal);
user.set('email',emailVal);
user.signUp(null, {
success: function(user) {
form.submit();
alert("Account Successfully Created!");
}, error: function(user,error){
alert("Account Not Created!");
}
});
});
});
</script>
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.