I have Registration.html fail, which contains registration form. The other failure is in KinveyRequester.js
function registerUser(e) {
e.preventDefault();
let userData = {
username: $("#registerUsername").val(),
password: $("#registerPassword").val()
};
$.ajax({
method: "POST",
url: kinveyBaseUrl + '/user/' + kinveyAppKey,
headers: kinveyAppAuthHeaders,
data: userData,
success: registerSuccess,
error: handleAjaxError
});
function registerSuccess(userInfo) {
saveAuthInSession(userInfo);
showInfo("User Successfully Registered");
}
The Question is:
How can i bind and when i clicked "Register" button it runs correctly and register a user. Here is the Register.html fail
You can bind registerUser function with your submit button simply by using jQuery on() method:
$(document).ready(function() {
$('#reg-btn').on('click', registerUser);
});
But it's better to bind on form's submit event:
$(document).ready(function() {
$('#your-form').on('submit', registerUser);
});
but in that case you have to return false at the end of the your registerUser function in order to prevent default submit behaviour.
for example like: $('input[type="submit"]').on( 'click', registerUser() );
or with a class for the submit button like $( document ).on( 'click', '.yourSubmitClass', registerUser() );
Do not bind the submit button, instead bind the form submit Also move the inline onload:
$(function() {
startApplication();
$("#registerUserForm").on("submit",registerUser);
});
Also you need a } between these:
});
} <<<<<<<<<<
function registerSuccess(userInfo) {
Example of the submit is here https://jsfiddle.net/2bvuc6on/ since StackSnippets block submit