2017-05-04 136 views
0

這是我的jquery:403禁止在笨

<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); 
    } 
} 

回答

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(); 

它在我的項目中實現的工作解決方案。希望這也能幫助你。

問候!

+0

謝謝你現在的工作:) –

+0

歡迎:)有樂趣@Yosra Ammar, –