如何在后台执行codeigniter控制器方法 [英] how to execute a codeigniter controller method in background

查看:41
本文介绍了如何在后台执行codeigniter控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个codeigniter的控制器功能,可以从gmail提取邮件.

I have a codeigniter's controller function that fetches mails from gmail.

这花费了很多时间,因此我需要在后台执行该特定的控制器功能,以便用户不必等到所有邮件都提取完之后.

It is taking lot of time so I need to execute that particular controller function in the background so that the user need not wait until all the mails are fetched.

推荐答案

Ajax Jquery Way

js:

$.ajax({
    url   : "index.php?/MyController/myMethod",
    async : true //change this to false if you hate your users and want them to wait 
}).done(function() {
    alert("EMAIL IS READY! USER DIDN'T WAIT")
});

php:

class MyController extends CI_Controller{

      function myMethod(){
          //do your email stuff
      }

      //if codgeIgniter V2
      function myMethod_get(){
          //do your email stuff
      }

}

这篇关于如何在后台执行codeigniter控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆