【发布时间】:2017-05-19 12:49:42
【问题描述】:
我正在尝试在 yii2 中使用 ajax 上传文件。 但它的浏览器控制台在我的 site_url 中显示 400 Bad Request 我的错是什么。。 请帮助任何人。
var site_url = '<?php echo Url::to (['formdata/movefile','id'=>'']); ?>' + unic ;
var file_data = $('#formdata-'+ form + '-' + component + '-c_data').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: site_url, // point to server-side PHP script
dataType: 'TEXT', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: { form_data:form_data,_csrf : '<?=Yii::$app->request->getCsrfToken()?>'},
type: 'POST',
success: function(php_script_response){
alert(php_script_response);
}
});
【问题讨论】: