相关疑难解决方法(0)

在laravel中上传AJAX文件

自从过去两天以来,我一直在努力让ajax文件上传工作在lavvel 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
  });
}
 });
Run Code Online (Sandbox Code Playgroud)

HTML块

 <form method="post" action="">
 <input type="file" id="basicModuleImage" name="basicModuleImage" />
 </form>
Run Code Online (Sandbox Code Playgroud)

LARAVEL PHP块

Route::post('upload', function(){

return Response::json(array('a'=>var_dump(Input::all()),'b'=>var_dump($_FILES)));

});
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用https://github.com/LPology/Simple-Ajax-Uploader,但这似乎与laravel有关.

JSON响应返回a和b都为null.

php ajax jquery laravel laravel-4

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

jquery ×1

laravel ×1

laravel-4 ×1

php ×1