Problem to load view

Asked

Viewed 219 times

1

Hello, I am consuming an API in my controller and, upon receiving the result, I would like to load a user panel view. But when the script arrives in the method $this->load>view() nothing happens. I debug to see if the information is coming into the controller and if the execution enters the conditional and the answer is yes, but the view is not loaded. I also tried to give a redirect('Controller/Action', 'refresh') but it also didn’t work, nothing happens. I appreciate if any can help.

Function that makes Submit for the controller:

    $('#form').validate({
    submitHandler: function () {
        $.ajax({
            type: 'GET',
            url: appPath + '/' + controller + '/' + action,
            dataType: 'JSON',
            data: $('#form').serialize(),
            cache: (false),
            async: (false),
            success: function (data) {
                alert(JSON.stringify(data));
            },
            error: function (err) {
                alert.log(err);
                //semanticAlert(err);
            }
        });
    }
});

.../controllers/User.php:

public function autenticar() {
    try {
        $credenciais = $this->input->get();

        $headers = array(
            'xAuthChaveApi: ' . API_KEY,
            'login: ' . $credenciais['login'],
            'senha: ' . $credenciais['senha']
        );

        $response = curlRequest('GET', Enum::authUsuario, $headers);

        if (isset($response['data']) && $response['meta']['status'] == 'success') {
            $this->session->set_userdata($response['data']);

            $dados = array(
                'titulo' => 'Painel de Controle',
                'nomeView' => 'dashboard/home'
            );

            $this->load->view('menu', $dados);
        }
        //echo json_encode($response['meta']);
    } catch (Exception $ex) {
        die($ex->getMessage());
    }
}
  • I am giving the html form Submit with Ajax. I will include the code in the post.

  • Dude, I want to render the menu with PHP and pass the recovered data by the curlRequest function to javascript to be able to manipulate Alerts and things like.

  • I made another issue in the post to be better understood. In this function I validate the form and send it to the controller, which in turn makes a request for an API that returns the user’s data, when data arrives in the controller I want to load a view and pass the data to javascript because based on the status returned by the Api I want to display a notification to the user.

  • I managed to make it work partially here, but as I’m loading the page and printing the answer at the same time gives error in calling Ajax (I think that’s why). How can I load the page and at the same time pass the API output message to the java script? Follow the current responseText: {"status":"Success","message":"User successfully authenticated." }<! DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8">....

  • I used ajax only to get the answer in javascript, I could have used standard Submit and use only PHP but I wish I could perform some operations based on the response I received from the API.

  • So I was just testing because when I get the answer what I’m going to do is show a notification with the text of the answer.

  • I really appreciate your patience. I dicidi leave PHP in charge of all these notifications, it will be in a more static way but without gambiarras. Thanks.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.