【发布时间】:2017-03-13 05:49:32
【问题描述】:
我有一个将用户插入数据库的表单。另一方面,我有两个密码验证脚本和检索 php 结果的 ajax 脚本。
现在这两个脚本是分开工作的。
我应该怎么做才能让 ajax 脚本在密码验证后运行?
密码验证
function Validate() {
var password = document.getElementById("UserPwd").value;
var confirmPassword = document.getElementById("ConfirmUserPwd").value;
if (password != confirmPassword) {
alert("Please enter the same password");
return false;
}
return true;
}
脚本
$.ajax({
url: "insert_sp.php",
method: "POST",
data: {submit: 'true'},
success: function(response) {
var data = JSON && JSON.parse(response) || $.parseJSON(response);
alert(data);
}
});
更新
isset : if(isset($_POST['Submit']))
按钮:<input type="submit" name="Submit" value="Submit"/>
$(function() {
$("#myForm").on("sumbit", function(e) {
e.preventDefault();
var password = $("#UserPwd").val(),
confirmPassword = $("#ConfirmPassword").val();
if ($.trim(password) === password &&
password !== "" &&
password === confirmPassword) {
$.ajax({
url: "insert_sp.php",
method: "POST",
data: {
submit: 'true'
},
success: function(response) {
var data = JSON && JSON.parse(response) || $.parseJSON(response);
alert(data);
}
});
}
else {
alert("Please enter the same password");
}
});
});
【问题讨论】:
-
现在这个问题不再有意义 - 但您仍然需要将
submit: 'true'更改为Submit: 'true'
标签: javascript jquery ajax validation