我通过ajax发送文件。而不是传递csrf令牌在控制器中不可用 贝娄是代码
<script type="text/javascript">
var csrfName = '<?php echo $this->security->get_csrf_token_name(); ?>',
csrfHash = '<?php echo $this->security->get_csrf_hash(); ?>';
$(document).on("change","#channel_setup_file",function(e){
var formData = new FormData($("#process-form")[0]);
$.ajax({
url: "<?php echo site_url('parse-setup-file')?>",
type: "POST",
data: {cform : formData,csrfName:csrfHash},
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
error: function(msg){
},
success: function(msg){
}
});
});
</script>
我只收到控制器中的网址。
答案 0 :(得分:0)
期望你在上下文中获得令牌和名称,因为我正在编写代码
var formData = new FormData($("#process-form")[0]);
$.ajax({
url: "<?php echo site_url('parse-setup-file')?>",
type: "POST",
data: {cform : formData,cName:csrfName,cToken:csrfHash},
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
error: function(msg){
},
success: function(msg){
}
});