當我做一個AJAX請求我去一個PHP腳本,爲我做一些事情。 它可以從db中刪除一條記錄,或者它不會。jQuery的AJAX - PHP的問題
如果沒問題。我想刪除並更新我的HTML表格。否則,我想顯示一條錯誤消息。
但在我的PHP,我不能這樣做
return false;
return true;
我需要我的呼應結果或者我的消息,然後我的jQuery腳本會用它做什麼。
但我怎麼能讓jquery根據結果做些什麼?
例如這裏:
jQuery.ajax({
type: "POST",
data: "id=" +id,
url: "ajax_handler.php",
success: function(msg){
jQuery(tr).remove();
jQuery("div.result").append("<p>"+msg+"</p>");
jQuery("div.result").show();
jQuery("div.result").fadeOut(5000);
},
error: function(msg){
}
和PHP代碼
$id = C_GPC::getPOSTvar("id");
$result ="";
if(isset($id) and ($id > 0)){
$p = new C_product();
$deleted = $p->deleteCategorie($id);
if($deleted){
$result = "ok";
}else{
$result = "not ok";
}
}else{
$result = "not ok";
}
echo $result;
我想做一個好時和B時,也不行。我應該如何處理這個問題? });