?? ????? ????? ??? ???? ????? ???? ???. ??? ??? ????, ?????? ???? ???? ????? ??? ???? ???? ?? ?????. ? ???? ?????. ??? ?? ??? ????
?? ??? ??? URL? ???????. ??? data.php? 6? $action ?????. ?? ?? ???? ?????? ??? ???????? ???? ??? ? ????. ???? PHP?? ??? ??? ????? ????
?? ?:
php:
//?? ??? Action? url? ???????. ??? data.php? 6?? ????.
$action = $_GET['??'];
???($??) {
'init_data_list'? ??:
init_data_list();
????;
?? 'add_row':
add_row();
????;
?? 'del_row':
del_row();
????;
?? 'edit_row':
edit_row();
????;
}
//?? ???, ?????? PHP? ??? ??????? ? ???? ?????? ??? ??? ? ????
?? del_row(){
//??
/*?? "???!";*/
//??? ????? ????.
$rowId = $_GET['rowId'];
$sql = "user_id='$rowId'? t_users?? ??";
if(query_sql($sql)){
?? "???!";
}? ??{
echo "?? ??!";
}
}
?? ?:
? ??? JS:
var $table = $('#table'),
$?? = $('#??');
$(??() {
?????();
????();
});
?? ????() {
$remove.on('??', function() {
if(confirm("?? ?????????")) {
var ? = $.map($table.bootstrapTable('getSelections'), function(row) {
//??? ?? ??? ??? ?????.
row.user_id? ?????.
});
}
$.map($table.bootstrapTable('getSelections'),function(row){
var del_url = "./php/data.php";
//userId? ???? ???? ?????. ? ID? ??? ???? ?????? ?????.
var rowId = row.user_id;
//PHP ?? ??? ?? ?? ??? ?????? del_row? ?? ???? ???.
/*var dataParam = {
??: "del_row",
rowId:rowId
};*/
$.???({
??:"??",
url:del_url + "?action=del_row&rowId=" + rowId,
??? ??:"html",
??? ??: 'application/json;charset=utf-8',
??: ??(???) {
$table.bootstrap???('??',{
??: 'user_id',
?: ?
});
$remove.prop('????', true);
},
??:??(???){
Alert('?? ??!');
}
});
});
})
}
?? ?:
???? ???? ?? 200?? ?????.
?? URL:http://localhost/muke/php/data.php?action=del_row&rowId=1
?? ??:DELETE
?? ??:200 OK
?? ??:[::1]:80
?? ??? ????
??:del_row
rowId:1
?????? ????, ?? ?? ???? ??? ????: 6?? data.php? ?? ??
??? ???? ?? ??????
?????? ?? ??, ?? ?? ???? ??? ????: 6?? data.php? ?? ??
??? ???? ?? ??????
Rest Client? ???? ???? ??? 200?? ??? ???? ??? ?? ?????! ?? ?????. ??? ????, ? ??? ? ??? ? ? ????. ?? ??? ???? PHP? del_row() ???? ???? ?? ?? ????. < br>
?>
??? ?? ????
???????? SQL ?? ?????. user_id='1'? t_users?? ??? ????? ???? ?????, ??? ????? ???? ??? ??? ????? ??? ??????. < /p>
????? ?? 4?? ??? ????:
??? ?? ??? ????? $_GET? ???? ?? ? ????.
SQL ?? ???? ?? ? ??? ???? ??? ??? ?????.
???????? SQL ?? ???? ?? ?? ???? ?????? ????? Rest Client? ???? URL ??? ???? ??????.
??? ?? ??? ??? ?????. ?? ?? ?????? ?? ?? ??? ? ????.
???
????? JS ???:
???
?? ??, ??????? ???:
?? ???? ???? ??? ?????? ???? $_GET ? $_POST? ???? ????? ??? ? ????.
?? ????? URL? ????? ???.
?????? action
放在body里了,自然$_GET
就取不到action
了,要用$_POST
。
看你都用了DELETE
方式提交了,不如改成restful
...
???
SQL ?? ??? ???? ???? ?? ? ???? ??????? ??? ? ???? ? ? ??? ???.
?? $_GET? ???? ??? ??? ?????.
??? ??? ?? ?????. dataType? json?? ??? ???
??? ???? ??? ?? ????? ?? ? ?? ?????