Jquery ajax success function returns null?

Posted by udaya on Stack Overflow See other posts from Stack Overflow or by udaya
Published on 2010-04-06T10:14:14Z Indexed on 2010/04/06 10:23 UTC
Read the original article Hit count: 459

Filed under:
|
|
|

I use the following the jquery statements to call my php controller function, it gets called but my result is not returned to my success function....

function getRecordspage() {
    $.ajax({
        type: "POST",
        url:"http://localhost/codeigniter_cup_myth/index.php/adminController/mainAccount",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        global:false,
        async: true,
        dataType: "json",
        success: function(result) {
           alert(result);
        }
    });
}

My controller method,

function mainAccount()
    {
        $_SESSION['menu'] = 'finance';
        $data['account'] = $this->adminmodel->getaccountDetails();
        if(empty($data['account']))
        {
            $data['comment'] = 'No record found !';
        }
        $json = json_encode($data);
        return $json;
}

I get the alert(1); in my success function but my alert(result); show null... Any suggestion...

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX