以下是我的代码;
$(document).ready(function(){
var fieldA = $('#fieldA').attr('value');
var fieldB = $('#fieldB').attr('value');
$('#simpleForm').validate({
errorLabelContainer: "#error_message_box",
wrapper: "li",
rules: {
firstname: "required",
fieldA: "required",
fieldB: {
required: true,
remote: "chk.php",
type: "POST",
dataType: "json",
data: "fieldA=" + fieldA + "fieldB=" + fieldB
}
},
messages: {
firstname: "Please enter your first name.",
fieldA: "Please enter field A.",
fieldB: {
required: "Please enter field B.",
remote: "Field B already exist."
}
}
});
});
我无法检查字段A和字段B是否都存在于MySQL同一个表中。
在PHP文件中只能获得fieldA,无法获取fieldB。
答案 0 :(得分:0)
应该是 -
data: "fieldA=" + fieldA + "&fieldB=" + fieldB
不是
data: "fieldA=" + fieldA + "fieldB=" + fieldB
我更喜欢使用 -
data : {
fieldA: fieldA,
fieldB: fieldB
}
因为它更容易构建和理解,虽然不确定validate是否支持这种格式,但$.ajax
确实支持它