<?php include_once "basicitemDB.php"; include_once "subitemDB.php"; $action = strtolower($_REQUEST["action"]); $res = array('status' => 'successful', 'errMsg' => ''); switch ($action) { case "addbunchbasicitems": $res = addBunchBasicItems($_POST); break; case "getbasicitems": $res = getBasicItems(); break; case "deletebasicitem": $id = $_POST['itemId']; deleteBasicItem($id); deleteBasicSubItemByParentId($id); break; case "editbasicitem": $res = editBasicItem($_POST); break; default: throw new Exception("unknown action:" . $action); } echo json_encode($res);
<?php include_once "basicitem.php"; include_once "basicsubitem.php"; $id = $_POST['itemId']; $resultOfItem = deleteBasicItem($id); $resultOfItem = json_decode($resultOfItem, true); $resultOfSubItem = deleteBasicSubItemByParentId($id); $resultOfSubItem = json_decode($resultOfSubItem, true); if ($resultOfItem["status"] == "successful" && $resultOfSubItem["status"] == "successful") { echo json_encode(array('status' => 'successful', 'errMsg' => '')); } else { if ($resultOfItem["status"] == "failing") { echo json_encode($resultOfItem); } else { if ($resultOfSubItem["status"] == "failing") { echo json_encode($resultOfSubItem); } } }