2017-05-30 50 views
0

我无法将数据发送到控制器。我的代码是:Codeigniter:如何使用ajax和csrf获取过程数据

var csrf = Cookies.get('truelogokoption'); 
$.ajax({ 
    url : baseURL +"checkout/hasilFilter", 
    type : "GET", 
    data : {destination: x, berat: y, courier: z} + "&starssecure=" + csrf, 
    success: function (ajaxData){ 
     //$('#tombol_export').show(); 
     //$('#hasilReport').show(); 
     $("#hasil").html(ajaxData); 
    } 
}); 

“数据”有问题吗?感谢

+0

此代码是在js文件或php文件? – ImBS

回答

0

检查这个它肯定帮助您解决问题

// Add This Code in your current view php file 
<input type="hidden" name="csrf_token" id="csrf_token" value="<?php echo $this->security->get_csrf_token_name(); ?>" /> 
<input type="hidden" name="csrf_token_value" id="csrf_token_value" value="<?php echo $this->security->get_csrf_hash(); ?>" /> 

// Change your js function according below 
var csrf_token = $("#csrf_token").val(); 
var csrf_token_value = $("#csrf_token_value").val(); 
$.ajax({ 
    url : baseURL +"checkout/hasilFilter", 
    type : "GET", 
    data : {destination: x, berat: y, courier: z, csrf_token: csrf_token_value}, 
    success: function (ajaxData){ 
     //$('#tombol_export').show(); 
     //$('#hasilReport').show(); 
     $("#hasil").html(ajaxData); 
    } 
}); 

希望你得到你的解决方案。任何问题评论框

+0

仍然错误先生..在我的代码中发生了什么? –

+0

这段代码在php文件中 –

+0

@DannySetyawan还有问题吗? – ImBS