当前返回[objectO
,而不是YES或No值。目前,我的复选框设置为长度为3的VARCHAR,但我应该使用TINYINT或Boolean吗。如果是这样的话,我需要做些什么才能让它发挥作用?任何帮助都将不胜感激。谢谢
("#add").click(function() {
var chkval = "";
if($('#checkbox').is(':checked')){
chkval = "Yes";
} else {
chkval = "No";
}
//define ajax config object
var ajaxOpts = {
type: "post",
url: "../controller/addComment.php",
data: "&module_ass=" + $("#leaveComment").find("input").val() + "&comment_body=" + $("#leaveComment").find("textarea").val() + "&private=" + $("#checkbox").val('chkval'),
success: function(data) {
您正在设置chkval
的值,所以以后只需要使用它:
("#add").click(function() {
var chkval = "";
if($('#checkbox').is(':checked')){
chkval = "Yes";
} else {
chkval = "No";
}
//define ajax config object
var ajaxOpts = {
type: "post",
url: "../controller/addComment.php",
data: "&module_ass=" + $("#leaveComment").find("input").val() + "&comment_body=" + $("#leaveComment").find("textarea").val() + "&private=" +chkval,
success: function(data) { ...
更新这是完整的代码和jsfiddle在这里:
$('#Volunteers').on('click','.accept', function(event){
//if clickFlag = true then the button hasn't been clicked yet.
if(typeof this._clickFlag != 'undefined' && this._clickFlag){
//alert if the button has been clicked once already
alert("already accepted");
}else{
//here I send some stuff to a database. I don't want to send it twice for the same
//row, which is why I need to prevent a double click
alert('_clickFlag: '+this._clickFlag + ' First time processing!');
this._clickFlag = true;
}
});
您应该能够简单地使用:
data: "&module_ass=" + $("#leaveComment").find("input").val() + "&comment_body=" + $("#leaveComment").find("textarea").val() + "&private=" + chkval,
由于变量是在上面指定的。您可能还想研究使用一个简单的bool,而不是字符串值"Yes"answers"No"。