2

誰でもこの単純なコードで私を助けることができますか?ユーザーが送信すると、テーブル内の1つのフィールドを更新するためにajaxリクエストを呼び出すjavascriptをロードするボタンがあるので、このメソッドを実行するコントローラーをajaxリクエストに渡しましたしかし、何も起こりません。これが私の見解です

 <!--body part--->
  echo "<button class='btn btn-info dropdown-toggle notify-btn' data-toggle='dropdown' 'href='#' value=".$count." onclick='notify(".$count.")'>".$count."</button>"; 

 <!--Here is my javascript--->

 function notify(count){
            $.ajax({
            type: 'POST',
           url:<?php echo base_url("notifications/set")?>,

        success:function(response){
            alert("Success");
        }
     });

            }

<!--Here is my Controller--->

     class Notifications extends CI_Controller{
     public function __construct()
     {
      parent::__construct();
      $this->load->model('notification_model');
     }

      public function index(){ 
         $this->set();
          }

        public function set(){
              $this->notification_model->set_notifications();
         }

<!--Here is my Model--->

 <?php class Notification_model extends CI_Model { 
            function set_notifications(){
                $this->db->where('notification_status','active');
                $this->db->set('notification_status',"inactive",FALSE);
                $this->db->update('messages');
            }
        }

?>
4

1 に答える 1

0

ざっと見てみると、URL が一重引用符で囲まれていないため、AJAX リクエストが失敗している可能性があります。次のことを試してください (URL が一重引用符で囲まれていることに注意してください)。

function notify(count){
    $.ajax({
        type: 'POST',
        url: '<?php echo base_url("notifications/set"); ?>',

        success:function(response){
            alert("Success");
        }
    });
}

それが役に立てば幸い...

于 2013-06-17T15:25:40.863 に答える