CodeIgniter Ajax空错误

Hi, guys. I'm new to Ajax, so I'm having a problem. When I press the supposed link to use Ajax, it shows an error message with the error parameter empty. What am I supposed to do?

I already tried to use base_url instead of site_url and it's no use. The structure of the click function is ok, I already tested it.

Thanks.

view.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js">  
    </script>
</head>

<body>
    <div id="barra_horizontal"> 
    </div>

    <div id="barra_vertical_esquerda">
        <ul id="nav">
        <?php 
            echo "<li><a href='' id='ntop' name='ntop'>Ntop</a></li>";
            foreach ($links as $l)
            {
                echo '<li>' . anchor($l['link'],$l['nome'], array('id'=>$l['id'])) . '</li>'; 
            }
        ?>
        </ul>
    </div>

    <div id="content">
        <?php 
            if (isset($content))
                {
                    include ($data[content]);
                }
        ?>
    </div>
    <script>
    $('#ntop').click(function(){
    $.ajax({    
        url: '<?php echo site_url('home/get_all_table/');?>',
        type:'POST',
        dataType: 'json',
        success: function(output_string){alert("Here!");},
        error: function (x, status, error) {
            alert("An error occurred: " + status + "
Error: " + error);
        }
    });
    }); 
    </script>
</body>
</html>

home.php

class Home extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        if ($this->session->userdata('logged_in'))
        {
            if (!$this->input->is_ajax_request())
            {
                $session_data = $this->session->userdata('logged_in');
                $data['links'] = array(
                    array('link'=>'/home/logout/','nome'=>'Logout','id'=>'logout')
                );

                $this->load->view('main_view', $data);
            }
            else {
                $data['links'] = array(                  
                    array('link'=>'/home/logout/','nome'=>'Logout')
                );
                $data['content'] = 'abcd.php';

                $this->load->view('main_view', $data);
            }
        }
        else
        {
            redirect('/','refresh');
        }
    }

    function get_all_table()
    {
        $this->load->model('usuario_model');
        $this->usuario_model->get_all_table();
    }
}

When you make an AJAX request, it's to a URL. Just like if you were to load that URL manually in your browser.

The URL usuario_model/get_all_table is not a correct URL. In CodeIgniter, you cannot call the model directly. You need to call a controller, and have that controller call the model.

You also have a syntax error near error line in status + Error:

  error: function (x, status, error) {alert("An error occurred: " + status +  
Error: " + error); }

This should like below

$('#ntop').click(function(){
 $.ajax({
     url: '<?php echo site_url("usuario_model/get_all_table");?>',
     type:'POST',
     dataType: 'json',
     success: function(output_string){ alert("Here!"); },
     error: function (x, status, error) {alert("An error occurred: " + status +"  
Error: " + error); }
 });
});

And you should call first controller and then your function in your function utilize your model

 url: '<?php echo site_url("controller/function");?>',

use this

<script>
    $('#ntop').click(function(){
        $.ajax({    
            url: '<?php echo base_url()."CONTROLLER_NAME/function_name/Parameters";?>',
            type:'POST',
            dataType: 'json',
            success: function(output_string){ alert(output_string); },
            error: function (x, status, error) {alert("An error occurred: "+status+"Error: "+error); }
        });
    }); 
</script>

In controller use this function after extending controller class, to get access to model

function __construct()
    {
        parent::__construct();
        $this->load->model('MODEL_NAME');

    }
function you_want_to_execute_troughh_ajax($Parameters)
{
$result = $this->MODEL_NAME->FUNCTION_OF_MODEL($parameters_needed);   
echo $result;

}