【发布时间】:2016-05-03 04:20:00
【问题描述】:
我正在尝试使用 FileDrop.js(最新版本)和 Laravel 5.1 来上传文件。
我已经在 routes.php 中为 ajax 请求设置了路由:
Route::any('/fileupload/ajax', ['as' => 'fileupload.ajax', 'uses' => 'FileUpload@ajaxRequest']);
以及用于在我各自的刀片中捕获文件丢失的 jquery 代码:
$('.filedrop')
.filedrop()
.on('fdsend', function (e, files) {
var ajaxUrl = '{{ route('fileupload.ajax') }}';
//code here
files.invoke('sendTo', ajaxUrl);
})
.on('filedone', function (e, file) {
//code here
});
问题在于 ajax 调用返回 Laravel 的“Page not found!”。
FileDrop.js 好像绕过了 laravel 路由。
任何想法。
【问题讨论】:
-
尝试将
/fileupload/ajax更改为fileupload/ajax,我认为第一个斜线不应该在那里 -
@Fester 完全一样。
-
如果您使用浏览器导航到路线会发生什么?
-
@Fester 它工作,返回 FileUpload@ajaxRequest 应该是。问题是 FileDrop 似乎绕过了 laravel 路由。
-
尝试使用
url('fileupload/ajax')而不是route('fileupload.ajax')。另外,您的 jquery 是否正在发送发布请求?在这种情况下,您需要包含一个 csrf 令牌
标签: jquery laravel laravel-routing filedrop.js