Welcome Guest, Not a member yet? Register   Sign In
Auto Refresh a function in controller
#2

[eluser]LuckyFella73[/eluser]
This is a code snipped I used to update my view:

Code:
var interval;

function Check_session() {
  
  $.ajax({
   url: ci_base_url + "controller_name/method_name",
   dataType: "json",
   success: function(data) {
    if (data.new_record == true) {
    
     closeInterval();
   // view update logic - display message - new post
    }
   }
  });
};

function startInterval(sec){
  
  interval = setInterval(function(){

   Check_session();

  }, sec);
};

function closeInterval(){
  clearInterval(interval);
};

startInterval(10000); // set your own value here

The var "ci_base_url" can be set hardcoded - I echo the value
using base_url() in my page header:

Code:
<scr +++ ipt type="text/java +++ script">
var ci_base_url = '&lt;?php echo base_url();?&gt;';
</scr +++ ipt>

I assume you load jquery to do the ajax request ..

Hope that get you on the right track.


Messages In This Thread
Auto Refresh a function in controller - by El Forum - 08-10-2012, 04:42 AM
Auto Refresh a function in controller - by El Forum - 08-10-2012, 04:50 AM
Auto Refresh a function in controller - by El Forum - 08-10-2012, 05:46 AM
Auto Refresh a function in controller - by El Forum - 08-10-2012, 05:52 AM
Auto Refresh a function in controller - by El Forum - 08-10-2012, 05:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB