Yosra Ammar
Yosra Ammar

Reputation: 3

403 Forbidden in codeigniter

This is my 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();

and this is my controller 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);
    }
}

Upvotes: 0

Views: 635

Answers (1)

Geee
Geee

Reputation: 2243

I think your method to access controller method with ajax is completely wrong. you don't need to specify full path. Here is the correct way to get access controller with 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();

It's working solution i have implemented in my project. Hope this will help you too.

Greetings!

Upvotes: 1

Related Questions