このスクリプトは、ユーザーがドロップダウンをクリックして別の選択を行い、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'
});
});