ajax请求
var saveFields = $.ajax({
url: '../P3_M3/ajax/saveform.php',
method: 'POST',
data: sqlInfo,
dataType: 'json',
error: function(error) {
console.log(error);
},
success: function (errorJSON) {
console.log(errorJSON['error']);
},
complete: function (jqXHR, textStatus){
console.log(`AJAX thinks edit save request was a ${textStatus}`);
$(".form-edit").fadeOut(300);
}
});
这就是我通常在saveform.php
$_POST['requestAction']; //gives me "save"
那么我怎么称呼checked
或unchecked
因为他们是一个阵列?
这样就足够了:
$checkedArr = $_POST['checked'] //will this give me an array?
foreach($checkedArr as $key => $value){ //can I do this?
echo "$key $value \n";
}
//Will this print?
// 0 1
// 1 2
//2 3
我也读过JSON.stringify
,我应该使用它吗?
答案 0 :(得分:0)
在你的html表单上只需添加一个复选框并为其命名,接下来你必须检查复选框是否为空,请参阅示例:
$var = $_POST['checkbox'];
if (empty($var)){
//nothing here
} else {
//run your script
}