Всем привет!
Есть проблема при передачи данных вводимых через форму..
console.log не выводит нечего в консоль..
Ивент не срабатывает..
Буду рад если кто сможет помочь...
function registerController(){
document.getElementById("reg_button").onsubmit = function(){
console.log("In the register");
var user = {
username:document.getElementById("reg_user_name").value,
firstname:document.getElementById("first_name").value,
lastname:document.getElementById("last_name").value,
userid:document.getElementById("user_id").value,
password:document.getElementById("reg_password").value,
email:document.getElementById("reg_email").value
}
console.log(user.username);
console.log(user.userid);
console.log(user.firstname);
console.log(user.lastname);
console.log(user.password);
console.log(user.email);
registerHandler(user);
}
}
function registerHandler(user){
console.log(user.username);
console.log(user.userid);
console.log(user.firstname);
console.log(user.lastname);
console.log(user.password);
console.log(user.email);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState!=4 && xhr.status!=200){
return window.alert(xhr.responseText);
}
}
xhr.open("POST","http://localhost:8080/CouponOnWeb/webappl/register",true);
xhr.setRequestHeader('Content-type','application/json;charset=utf-8');
xhr.send(user);
}
<form id = "registrator" onsubmit = "registerController()">
<label for = "reg_user_name">User name:</label>
<input id = "reg_user_name" name = "reg_user_name" type = "text" placeholder = "user name">
<br>
<label for = "first_name">First name:</label>
<input id = "first_name" name = "first_name" type = "text" placeholder = "first name">
<br>
<label for = "last_name">Last name:</label>
<input id = "last_name" name = "last_name" type = "text" placeholder = "last name">
<br>
<label for = "user_id">Id number:</label>
<input id = "user_id" name = "user_id" type = "number" placeholder = "id number">
<br>
<label for = "reg_password">Password:</label>
<input id = "reg_password" name = "reg_password" type = "text" placeholder = "password">
<br>
<label for = "reg_email">Email:</label>
<input id = "reg_email" name = "reg_email" type = "email" placeholder = "email">
<br>
<input id = "reg_button" name = "reg_button" type = "submit" value = "Register">
</form>