【问题标题】:403 Forbidden in codeigniter403 在 codeigniter 中被禁止
【发布时间】:2017-05-04 08:27:59
【问题描述】:

这是我的 jquery:

<script type="text/javascript">
function notif() {
    $.ajax({

        url: "<?php echo base_url('application/controllers/Notification.php/countNotif');?>",
        ifModified:true,
        success: function(content){
            $('#notifications').html(content); //span où tu veux que ce nombre apparaisse
        }
    });
    setTimeout(notif, 10000);
}
notif();

这是我的控制器 Notification.php:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Notification extends CI_Controller
{
    var $type;//reservation request, comment, message
    var $to_user;
    var $from_user;
    var $reference;//comm id, message id
    var $timestamp;
    var $newcount;

    function __construct()
    {
        parent::__construct();
        $this->load->library('session');
        $this->load->model('notif_model');
    }

    public function countNotif()
    {
        $id =$this->session->userdata('id');
        $data['nb']=$this->notif_model->countNotif($id);
        $this->load->view('nombre',$data);
    }
}

【问题讨论】:

    标签: jquery codeigniter


    【解决方案1】:

    我认为您使用 ajax 访问控制器方法的方法是完全错误的。 您不需要指定完整路径。下面是用ajax获取访问控制器的正确方法:

    <script type="text/javascript">
        function notif() {
            $.ajax({
                url: "<?php echo base_url('index.php/Notification/countNotif');?>",
                ifModified:true,
                success: function(content){
                    $('#notifications').html(content); //span où tu veux que ce nombre apparaisse
                }
           });
           setTimeout(notif, 10000);
        }
        notif();
    

    这是我在项目中实施的有效解决方案。希望这对您也有帮助。

    您好!

    【讨论】:

    • 欢迎 :) 玩得开心@Yosra Ammar,
    猜你喜欢
    • 2021-04-04
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-23
    • 2011-10-21
    • 2019-04-01
    相关资源
    最近更新 更多