echo json_encode只是在浏览器中显示数据而jquery无法获取它(PHP MVC)

i built my own PHP MVC website . i want the admin can see the data's without refresh using jQuery and getJSON function

index method in admins controller

public function index(){
    session_start();
    if($this->isLogin()){
        echo json_encode($this->adminModel->getAdsWithNoPermission());

    }else{
        die("404 NOT FOUND");
    }

}

Home method in admins controller

public function home(){
    session_start();
    if($this->isLogin()){
        $this->view('admin/index');
    }else{
        redirect('pages/notfound');
    }
}

Jquery script in admin/index view

function adsOutput(){
    $.getJSON('<?php echo URL_ROOT;?>admins/index',function(data){
        var adminid = '<?php echo $_SESSION['admin_id'];?>';
        $.each(data,function(i,item){
            $('#adsOutput').append('<tr>');
            $('#adsOutput').append('<th score="row">' + i);
            $('#adsOutput').append('<td>' + data[i].title + '</td>');
            $('#adsOutput').append('<td>' + data[i].subject + '</td>');
            $('#adsOutput').append('<td>' + data[i].description + '</td>');
            $("#adsOutput").append('<td><input type="submit" class="publish btn btn-success" value="publish" adid=' + data[i].id +  ' adminid=' +adminid +' ><input type="submit" class="delete btn btn-danger" value="delete" adid=' + data[i].id +  ' adminid=' +adminid +' ></td>' );

            console.log(data);

        })
    })
}

as you can see i wrote 2 methods home and index . the index just echo the data comes from model in json way . and the home return the homepage views . in the jquery function i'm getting json file from index page and shows data in the html. codes works correctly but i want to know how can i have just one index method like this

public function index(){
session_start();
if($this->isLogin()){
    echo json_encode($this->adminModel->getAdsWithNoPermission());
    $this->view('admins/index');
}else{
    die("404 NOT FOUND");
}

}

because when i wrote the index like this and remove the home method the output is this : https://pasteboard.co/Hw62NKh.jpg

and if there is no way that i can handle all things in index method, and home method needs to be exist , how can i hide index methods (avoid admin to get there by URL) just to use it for jquery .

You can't combine two request like this. The index function should only return one thing, the page. Perhaps you could add an "arguments" parameter to your view method like

$this->view('admins/index',$this->adminModel->getAdsWithNoPermission());

And in your view, echo out the data into a JS object or HTML.

Note, you should set content type when you output JSON data. e.g.

header('Content-Type: application/json');