dousi8559 2013-09-09 22:29
浏览 42
已采纳

如何在Codeigniter中加载任何特定视图页面之前调用ajax函数

I have a view page below which automatically detects the current user timezone and after detecting timezone , i am sending it to another page for setting the timezone in session for further use.

here is the file(autodetect.php)

<!DOCTYPE html>
<html>
<head> 
    <title>   
    <script type="text/javascript" src="....jquery.js' ?>"></script>  
      <script type="text/javascript"       src='..autodetect/Jsfile/detect1.0.4.min.js'>   
</script> 
 <script>  
 $(function() {   

   <?php if (!isset($_SESSION['tz'])) { ?>
        var timezone = jstz.determine(); 
        $.ajax({
            type: "POST",
            url:"<?php echo base_url('timezone.php'); ?>",
            data: 'timezone='+timezone.name(),
            success: function(data){ 
            }
        }); 
        <?php } ?>   
    }); 
 </script>   
 </head> 
 <body>  
 </body>

,in order to perform this functionality i have to load/read this page(autodetect.php) first,

so my question is "how can i run this page(i.e autodetect.php) before loading any view page or calling any view page via controller?

eg. i have to load the signup page , but before then this i need to read the above php file in order to detect the current timezone of user.

  • 写回答

1条回答 默认 最新

  • douyi1966 2013-09-12 18:03
    关注

    To load any script before loading any view page, you can use Hooks:

    Hooks - Extending the Framework Core

    And choose the appropriate hook point for your need.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!