开发者

Cakephp jquery debug info inside the ajax response

I have a cakephp code that works with the database to search a given card id number and return the balance. the jquery code looks like this.

function subm(event){
    $.ajax({
    type: "POST",
    //contentType: "application/json; charset=utf-8",
    dataType:'json',    
    url:"\/balances\/balance",
    data:$("#button_check_balance").closest("form").serialize(), 
    cache: false,                   
    beforeSend:function(){                              
        $("#loadingDiv").show(1000);
    },
    success:function (data, textStatus,xhr) {
        $("#loadingDivision").hide(1000);
        alert("balance is "+data.balance);
        return false;
    },
    //failure: function(msg){alert(msg);},
    error: function(xhr, ajaxOptions, thrownError){
        $("#loadingDivision").hide(1000);
        alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
        console.log(xhr.responseText);
    },
    /*complete: function(){
        alert("complete");
    },*/

});

I have the balancesController and balance.ctp files in place and controller logic looks like this.

function balance() {
    $message = "";
    $error = "";
    $this->layout = 'ajax'; //layout should be ajax based on
    Configure::write('debug', 0);
    //gets the submitted card number
    $card_id = $this->data['balances']['cardId']; //entered card id of the emp
    if (!empty($this->data)) {
        $this->header('Content-Type: application/json');
        try {
            $card = $this->Card->getBalance($card_id);
        } catch (Exception $e) {             
            $error = "balance not available";
            $resp = json_encode(array('error' => $error));
            echo $resp;
            exit;
        }
        if ($this->RequestHandler->isAjax()) {
            $this->autoRender = $this->layout = false;
            $resp = json开发者_如何学编程_encode(array('cardData' => $cardObj);
            echo $resp;
            exit;
        }
    }
}

th problem that I have is - when a balance not available error is occurred "I AM GETTING THE CAKE DEBUG INFOMATION IN MY AJAX RESPONSE."

eg - when I try to access xhr object inside error function on $.ajax event using "xhr.responseText" I am getting the long output consisting of <pre class="cake-debug">.......... and at the end of this ONLY I get the error that I have encoded into json. {"error":"error...."} I have used Configure::write('debug', 1); and Configure::write('debug', 0); without any luck.as u can see I used Configure::write('debug', 0); in the top of my controller function as well.. please advice me resolve this issue. all your input is very highly appreciated.


If you're getting the debug message that means you have an error in your code and you should fix it instead of hiding it. Read the error message (or paste it here) to find out and fix the problem

You're using a throw/catch. Cake usually does not use exceptions to handle errors, unless you've specifically coded your model to throw exceptions, your error state won't be captured. Possibly $card is just returning false.

Please paste your error here, or on pastebin if it's really long.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜