Activate controller when refreshing page

Asked

Viewed 34 times

-1

Good, I am building a Dashboard where I want ,while refreshing my page, it triggers the 'Notification' controller that will return me values from a database.

My question is, how can I trigger the controller by refreshing the page? My idea is to use the onload event but I don’t know how I do the function to trigger the controller.

If anyone can help me, I’d appreciate it!

  • 1

    The controller’s responsibility is to respond to an HTTP request. If you want to trigger it, just send a request to the URL it will have; you can do this with asynchronous requests in the browser.

  • Therefore, ajax?

1 answer

0

As I understand it, I think you want the following:

Using jQuery

<script type="text/javascript">

   $(document).ready(function() {

    notificacoes();

   });

 function notificacoes(){

    $.post("<?=base_url('notificacoes/buscar')?>",
            {},
            function(data){

              //faça o que quiser aqui

            }
    );
 }

</script>

Browser other questions tagged

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