1

このスクリプトは、ユーザーがドロップダウンをクリックして別の選択を行い、defaultCharacterID というセッション キーを変更したときに実行されます。リクエストは許可されていません。

PHP:

public function changeDefaultCharacter()
{
    if ($this->input->post('defaultCharacterID'))
    {
        $this->session->set_userdata($this->input->post('defaultCharacterID'));
    }
}

jQuery:

$(document).ready(function() {
    $('#charactersDrop').change(function() {
    // POST the changed value to a method in a controller that can accept
    // a parameter and that'll set the session variable for you
        $.post('dashboard/changeDefaultCharacter',
          { defaultCharacterID: this.value },
           'html'
          ); 
    });
});

編集:

$(document).ready(function() {
$('#charactersDrop').change(function() {
    // POST the changed value to a method in a controller that can accept
    // a parameter and that'll set the session variable for you
    $.post('dashboard/changeDefaultCharacter',
      { defaultRosterListID: this.value },
      <?php echo $this->security->get_csrf_token_name(). ':'. 
           $this->security->get_csrf_hash(); ?>
      }
   ,
   'html'
});
});
4

1 に答える 1

0

変更config.phpして、次のことを確認してください。

   $config['csrf_protection'] = FALSE; 

このエラーの原因は、セッショントークンをチェックしているajax保護が原因です。1つのコントローラーに対してのみ一時的にオフにすることもできます

  $this->config->set_item("csrf_protection",FALSE);

更新しました

または、保護を残してリクエストtrueに追加することをお勧めしますcsrf token

$.post('dashboard/changeDefaultCharacter',
      {
         defaultCharacterID: this.value, 
        <?php echo $this->security->get_csrf_token_name(). ':'. 
               $this->security->get_csrf_hash();
        ?>
       }
       ,
       'html'
      );
   ...
于 2012-04-09T13:45:06.470 に答える