这是我写的用于验证后提交表单的脚本,并使用$ _POST在php文件中接收值,但我没有在php文件中获取值。当我试图回应那些在php中显示空白的值。请指导我,我是jquery的新手
<script>
$("#changepassform").validate({
rules: {
old_password: "required",
password: "required",
password2: {
equalTo: "#password"
},
},
messages: {
old_password: "Please enter old password",
password: "Please enter new password",
password2: " Enter Confirm Password Same as Password"
},
submitHandler: function(form) {
var current_password = $("#current_password").val();
var new_password = $("#password").val();
var comfirm_password = $("#password2").val();
var id = $("#id").val();
var dataString = 'newpassword1=' + new_password + '&id1=' + id;
$.ajax({
type: "POST",
url: "changepassword.php",
data: "dataString",
success: function(response) {
$("#status").html(response);
}
});
}
//form.submit();
//return false;
});
// required to block normal submit since you used ajax
//form.submit();
</script>
答案 0 :(得分:0)
发送数据时出错..
<script>
$("#changepassform").validate({
rules: {
old_password: "required",
password: "required",
password2: {
equalTo: "#password"
},
},
messages: {
old_password: "Please enter old password",
password: "Please enter new password",
password2: " Enter Confirm Password Same as Password"
},
submitHandler: function(form) {
var current_password = $("#current_password").val();
var new_password = $("#password").val();
var comfirm_password = $("#password2").val();
var id = $("#id").val();
var dataString = 'newpassword1=' + new_password + '&id1=' + id;
$.ajax({
type: "POST",
url: "changepassword.php",
data: dataString,
success: function(response) {
$("#status").html(response);
}
});
}
//form.submit();
//return false;
});
// required to block normal submit since you used ajax
//form.submit();
</script>
使用serialize()
方法。在发出AJAX请求时,可以在URL查询字符串中使用序列化值。