目前,我正在尝试通过jQuerys验证插件来解析两个值,以对照SQL数据库进行检查。我可以看到DateReceived已正确解析,但是CentreID始终显示为null。
这是我当前的代码:
var centreID = $( '#CentreSelect' ).val();
$("#submit-form").validate({
rules: {
DateReceived:{
required: true,
remote:{
url: "url.php?CentreID=" + centreID,
type: "GET"
}
},
},
messages: {
DateReceived: {
remote: "Error - Centre already entered on that date"
}
}
});
});
一个建议将不胜感激。
最佳答案
你需要
$("#submit-form").validate({
rules: {
DateReceived: {
required: true,
remote: {
url: "url.php?CentreID=" + centreID,
data: {
CentreID: function () {
//you need to read this value when the validation is executed, so pass the value as a function which will be called
return $('#CentreSelect').val()
}
}
type: "GET"
}
},
},
messages: {
DateReceived: {
remote: "Error - Centre already entered on that date"
}
}
});