在交换机中使用声明的变量

时间:2014-08-29 15:59:16

标签: php jquery ajax switch-statement case

我正在使用submit, delete, or cancel切换。我不知道我做错了什么,但我无法访问提交的任何输入的值。我可以在开关外面回应它们,它们工作正常。

这是Ajax:

function check_url(recieve_url, type) {
    if (recieve_url == undefined || recieve_url == null) {
        alert("recieve_url is not set!");
    }
    $.ajax({
        url : recieve_url,
        type : 'POST',
        dataType : 'json',
        data : "type="+type,
        success : function (result) {
            //alert(result['bg'] + result['message'] + result['caption'])

            myApp.alert(result['message'], result['title'], function () {
                if (result['redirect'] != null || result['redirect'] != undefined){
                    window.location = "<?php echo $this->url;?>"+result['redirect'];
                }
            });
                //myApp.alert(result['message'], result['title']);


        },
        error : function (xhr, ajaxOptions, thrownError) {
            myApp.alert(xhr.responseText);
            myApp.alert(xhr.status);
            myApp.alert(thrownError);
        }
    })

}

这是PHP:

function EditSubmit($ID = ''){
    //get the case name to direct to
    $type = htmlspecialchars(trim($_POST["type"]));
    $sql = "SELECT * FROM staff WHERE id = :id";
    $arr  = array(":id" => $ID);
    $result = $this->database->DBQry($sql, $arr);
    $id = $result[0]['id'];
    $email = $result[0]['email'];
    $admin = $result[0]['admin'];
    $staff = $result[0]['staff'];
    $disabled = $result[0]['disabled'];
    $active = $result[0]['active'];
    $admin_check = isset($_POST['admin_check']);
    $address = isset($_POST['address']) ? $_POST['address'] : '';
    echo $address.' '.$admin_check;

    switch ($type) {
        case 'submit':
        if ($admin == 1){
            $response = array(
                'message' => 'Cannot edit an administrator',
                'title' => 'Error'
                );
        }else{
            $arr = array(":address" => $address, ":admin" => $admin_check, ":staff" => 1, ":disabled" => 1, ":active" => 1);
            $this->database->DBSet($arr,'staff',$whr = 'WHERE id = '.$ID);
            $response = array(
                'message' => 'active'.$address.' admin'.$_SESSION['qun'].' staff'.$staff_box.' disabled'.$disabled_box,
                'title' => 'Success',
                'redirect' => 'Staff/Edit'
                );
        }
        break;
        case 'delete':
        if ($admin == 1){
            $response = array(
                'message' => 'Cannot delete an administrator',
                'title' => 'Error'
                );
        }else{
            $this->database->DBDel('staff',$whr = 'WHERE ID = '.$ID);
            $response = array(
                'message' => 'Staff member deleted',
                'title' => 'Success',
                'redirect' => 'Staff/Edit'
                );
        }
        break;
        case 'cancel':
        $response = array(
            'message' => 'Nothing has been changed',
            'title' => 'Canceled',
            'redirect' => 'Staff/Edit'
            );
        break;
    }


    echo json_encode($response);

}

我可以在切换之前echo。所以我迷失了为什么我不能在开关内使用它们。

0 个答案:

没有答案