2014-11-09 16 views
1

我當前使用的笨,我想菜單 上創建通知在控制器如何使用codeigniter將數據傳遞到ajax?

class Notes extends Frontend_controller{ 

    public function __construct() { 
     parent::__construct(); 
    } 
    public function index(){ 

     $this->data['data'] = array(
      'fuck'=>'fuck', 
      'fucks'=>'fuckf', 
      'fuckf'=>'fucks', 
     ); 
     $this->load->view('templates/notification/notification',$this->data); 
    } 
} 

這裏是我的回波數據查看 在View

<li> 
     <?PHP foreach($data as $data){ 
     echo $data; 
     } ?> 
    </li> 

最後我jQuery的AJAX調用

<script> 
    $(function() { 
     var data = document.getElementsByTagName("li").val(); 
     $.ajax({ 
      type: "POST", 
      url: "<?PHP echo base_url("/notes/notes") ?>", 
      data: data, 
      contentType: 'application/json; charset=utf-8', 
      dataType: 'html', 
      async: true, 
      cache: false, 
      success: function(res) { 
       $("#notes").html(res); 
      } 
     }); 
     return false; 
    }); 
</script> 

結果我收到如下錯誤

我怎會現在請幫 未捕獲的ReferenceError:$沒有定義

回答

1

您可能還沒有包括JQuery的在你的代碼

+0

我已經加載它 – hengsopheak 2014-11-09 06:34:48

+0

哦,你是對的,因爲我把Ajax調用下面的jQuery庫調用謝謝 – hengsopheak 2014-11-09 06:43:27

相關問題