Skip to content

Instantly share code, notes, and snippets.

@kresnasatya
Created December 29, 2016 22:00
Show Gist options
  • Save kresnasatya/05c98a29284db516ebba558f7adf666b to your computer and use it in GitHub Desktop.
Save kresnasatya/05c98a29284db516ebba558f7adf666b to your computer and use it in GitHub Desktop.
Form contain CSRF code and AJAX
// So, this is the part of file add.php which is this is located in application/views in CodeIgniter
<script src="<?php echo base_url('assets/js/jquery.min.js');?>" charset="utf-8"></script>
<!-- So, for make CSRF working more times, you should use cookie plugin -->
<script src="<?php echo base_url('assets/js/jquery.cookie.js'); ?>" charset="utf-8"></script>
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>" charset="utf-8"></script>
<script>
/* Ajax Dropdown Jurusan Prodi */
function getProdi(value) {
console.log(value);
var row = value;
var csrf = $.cookie('csrf_cookie');
$.ajax({
type: "POST",
url: "<?php echo site_url('mahasiswa/get_prodi');?>",
// Add csrf_test_name: $.cookie('csrf_cookie_name') to your data
data: {row, csrf_token: csrf},
success: function(data) {
$("#prodi").html(data);
console.log(data);
},
error:function(XMLHttpRequest){
alert(XMLHttpRequest.responseText);
}
});
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment