将javascript数组发送到控制器并加载视图[关闭]

Sorry I'm a newbie in web programming. I have a problem to send array from Javascript / JS array to my function in controller and load new view.

I try to use ajax and I can read that array but ajax not load new view, how to do that?

Please tell me the correct way to send javascript array to controller and load new view.

Please help.

Here's my javascript:

$.ajax({
    type: "POST",
    url: "<?= base_url() ?>index.php/test/coba",
    data: { 
        test: "test"
    }
});

and my controller test.php

function coba() {
    $data['test'] = $this->input->post('test');
    $this->load->view('newview',$data);
}

Please help

AJAX is meant to send or receive data from the client side to the server side. You can't display a view by using an AJAX method, what you could do, however, is receive values that could then be displayed by using Javascript code.

But AJAX is mainly used to give the client the possibility to interact with the database, which doesn't seem to be what you are trying to do, are you sure you need to use AJAX?

If you need to display something depending on user behaviour, without requiring database calls, then Javascript should be all you need. You could add the HTML code with PHP, and hide it, and when the user does the specific action, you can fill what needs to be filled and display your content.