我正在尝试将信息从表单插入到数据库中。这是 html 中的表单 - 尝试发布和获取。
<form id="register" action="script/register.js" method="post">
<label for="username">Username:</label>
<input type="text" name="username" id="username" placeholder="Username" />
<br>
<label for="passd">Password:</label>
<input type="password" name="passd" id="passd" placeholder="Password" />
<br>
<label for="conpassd">Password:</label>
<input type ="password" name="conpassd" id="conpassd" placeholder="re-type Password"/>
<br>
<label for="email">E-Mail:</label>
<input type="text" name="email" id="email" placeholder="Email address"/>
<br>
<br>
<button type="submit" name="submitMe" id="submitMe">Submit</button>
<button type="reset">Clear</button>
</form>
这是脚本
$(document).ready(function() {
var usernameCorrect = false;
var passwordCorrect = false;
function checkPassword() {
var p1 = $("#passd").val();
var p2 = $("#conpassd").val();
if(p1 == p2) {
passwordCorrect = true;
} else {
passwordCorrect = false;
alert("Passwords does not match");
}
}
function checkUsername() {
var user = $("#username").val();
var dataPass = {
"username": user
}
$.ajax({
url: "server/userExists.cgi",
type: "GET",
dataType: "text",
data: dataPass,
success: function(data) {
var user = $.trim(data);
if(user == "No") {
usernameCorrect = true;
} else if(user == "Yes") {
usernameCorrect = false;
alert("Username already in use");
}
},
error: function() {
alert('Script Execution Error');
},
});
}
function submitForm() {
if(usernameCorrect == true && passwordCorrect == true) {
e.preventDefault();
var dataPass = {
'username': (username),
'passd': ($("#passd").val()),
'email': ($("#conpassd").val())
};
$.ajax({
url: "server/init.cgi",
type: "GET",
data: dataPass,
success: function() {
alert("Register successful");
//nextPage(username);
},
error: function() {
alert("Error!");
},
});
}
}
$("#submitMe").click(function(e) {
submitForm();
});
});
无论如何将表单链接到javascript?我不知道任何其他语言,例如 php 所以...谢谢