Auto refresh data through Model |
HI Everyone
i'm totaly new to MVC programming and CodeIgniter, so please forgive me for basic question. I couldn't figure it out myself. I have a controller called "dashboard.php" I have a model called "members_model.php" I have a view called "dashboard_view.php" In my controller I call : $this->load->model('members_model'); $resultdata["membersTotal"] = $this->members_model->Get_Total(); The Get_Total() function returns me a number. Inside my dashboard_view I have a <div id="membertotal"> in which I echo out $membersTotal and this works fine. However, now I want to refresh that data in that <div> every 5 seconds. I know I need to do an AJAX call , but how do I call that model dashboard_model.php to retrieve the new value ? Hopefully it's somewhat clear, thanks guys!
You will probably want to create a new function in Dashboard. Let's call it refresh_count().
The URL you will tell your AJAX to visit will be https://example.com/dashboard/refresh_count refresh_count() will also use the same model and make the call PHP Code: $this->members_model->Get_Total(); What you do with the return from that depends on how you set up your AJAX. There are many possibilities and almost none of them are wrong.
Thank you Dave, that's exactly what I tried to do now , but no matter what I write in the URL it always returns 404 not found.
I think something is wrong with my htaccess or routing ... not sure. htaccess : RewriteEngine on RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png) RewriteCond %(REQUEST_FILENAME) !-f RewriteCond %(REQUEST_FILENAME) !-d RewriteRule ^(.*)$ ./index.php/$1 [L]
|
Welcome Guest, Not a member yet? Register Sign In |