【发布时间】:2014-04-19 09:49:10
【问题描述】:
自从过去两天以来,我一直在尝试让 ajax 文件上传在 lavavel 4 中工作,但我现在很不走运。
我的 jquery 块
$(document).ready(function(){
$('#basicModuleImage').change(function () {
sendFile(this.files[0]);
});
function sendFile(file) {
$.ajax({
type: 'post',
url: '/upload',
data: file,
enctype: 'multipart/form-data',
success: function (data) {
alert(data);
},
processData: false,
contentType: file.type
});
}
});
HTML 块
<form method="post" action="">
<input type="file" id="basicModuleImage" name="basicModuleImage" />
</form>
LARAVEL PHP 块
Route::post('upload', function(){
return Response::json(array('a'=>var_dump(Input::all()),'b'=>var_dump($_FILES)));
});
我也尝试过使用https://github.com/LPology/Simple-Ajax-Uploader,但这似乎是 laravel 的问题。
JSON 响应返回 a 和 b 均为 null。
【问题讨论】:
标签: php jquery ajax laravel laravel-4