未捕获引用错误:未定义用户名

pdsfdshx  于 2021-09-29  发布在  Java
关注(0)|答案(2)|浏览(346)

未捕获引用错误:register.html中未定义用户名?username=petra+meier&email=petra%40meier.de&password=1234598&repeat\u password=123459:126(匿名)@register.html?username=petra+meier&email=petra%40meier.de&password=1234598&repeat\u password=123459:126
问题出在内部 data ```
$.ajax({
method: "POST",
url: "p.php",
data: {
signUp_username: username,
signUp_email: email,
signUp_pass: password,
pass_again: password_proof
}

@import url('https://fonts.googleapis.com/css?family=Montserrat:400,800');

$('#switch_login').click(function() {
location.href = "http://localhost/Manage/dujic/login_3.html?#";
});

$('#register').click(function() {
$debug = false;

username = $('#signUp_username').val();
console.log(username);

email = $('#signUp_email').val();
console.log(email);

password = $('#signUp_pass').val();
console.log(password);

repeat_password = $('#pass_again').val();
console.log(repeat_password);

//1
if (!isUsername(username)) {
if ($debug)
displayMessageBox('#message', 'Bitte gültige Username eintragen!');

$('#signUp_username').focus();
$('#signUp_username').css('background-color:red');
return;

}

//2
if (!isEmail(email)) {
if ($debug)
displayMessageBox('#message', 'Bitte gültige E-Mail eintragen!');

$('#signUp_email').focus();
$('#signUp_email').css('background-color:red');
return;

}

//3
if (!isPassword(password)) {
if ($debug)
displayMessageBox('#message', 'Bitte gültiges Kennwort eintragen!');

$('#signUp_pass').focus();
$('#signUp_pass').css('background-color:red');
return;

}

//4
if (!isPassword_proof(password_proof)) {
if ($debug)
displayMessageBox('#message', 'Bitte gültiges Kennwort eintragen!');

$('#pass_again').focus();
$('#pass_again').css('background-color:red');
return;

}

if (isUsername(username) && isEmail(email) && isPassword(password) && isPassword_proof(repeat_password)) {
if ($debug)
displayMessageBox('#message', '');

$('#signUp_username').css('background-color', 'white');
$('#signUp_email').css('background-color', 'white');
$('#signUp_pass').css('background-color', 'white');
$('#pass_again').css('background-color', 'white');

if ($('#message').is(":visible")) {
  $('#message').toggle();
}

}
})

$.ajax({
method: "POST",
url: "p.php",
data: {
signUp_username: username,
signUp_email: email,
signUp_pass: password,
pass_again: password_proof
}
}).done(function(msg) {
if ($debug) displayMessageBox('#message', msg);
if (msg == true) {
location.href = 'http://localhost/Manage/login_3.html?#';
} else {
displayMessageBox('#message', 'Sign In failed');
}
});

function isUsername(username) {
var regex = /^([a-zA-Z0-9_.+-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(username);
}

function isEmail(email) {
var regex = /^([a-zA-Z0-9_.+-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}

function isPassword(password) {
if (password == "" || password.length < 4) {
return false;
} else {
var regex = /[A-Za-z0-9_]/;
return regex.test(password);
}
}

function isPassword_proof(password_proof) {
if (password == "" || password.length < 4) {
return false;
} else {
var regex = /[A-Za-z0-9_]/;
return regex.test(password);
}
}

function displayMessageBox(boxName, BoxContent) {
if ($(boxName).is(':hidden')) {
$(boxName).toggle();
}
$(boxName).text(BoxContent);
}

ulmd4ohb

ulmd4ohb1#

var username = $('#signUp_username').val();console.log(username);
var email = $('#signUp_email').val(); console.log(email);
var password = $('#signUp_pass').val();console.log(password);
var repeat_password = $('#pass_again').val();console.log(repeat_password);

<input type ="text" name="username" placeholder="Username" id="signUp_username" />
<input type ="email" name="email" placeholder="Email" id="signUp_email" />
<input type="password" name="password" placeholder="Password" id="signUp_pass" /> 
<input type="password" name="repeat_password" placeholder="Password_proof" id="pass_again" />
smdnsysy

smdnsysy2#

声明用户名、电子邮件。。。等功能之外。
然后使用: username = $('#signUp_username').val(); 在…内

相关问题