【发布时间】:2013-12-18 02:06:28
【问题描述】:
我正在使用 Angular 上传图像(以及同时的其他数据),并使用 Angular 服务传递给 Laravel 的路由,所有这些都使用 javascript 中的 FormData 函数。这是我的上传代码(在coffeescript中):
tag = null
if $('span.tag').length > 0
tag = $('span.tag').map(->
$.trim @innerHTML
).get().join(",")
fd = new FormData()
fd.append "title", $scope.title
fd.append "subtitle", $scope.subtitle
fd.append "date", $scope.date
fd.append "time", $scope.time
fd.append "category", $scope.category
fd.append "content", $scope.content
fd.append "tag", $scope.tag
fd.append "caption", $scope.caption
fd.append "active", !$scope.active
if $scope.file
fd.append "image", $scope.file
alert fd
UploadService.news.save fd
, ( (response) ->
alert response.data
)
而我的UploadService就是这个,指向Laravel的路线:
app.factory "UploadService", ["$resource", ($resource) ->
news: $resource("upload/news")
member: $resource("404/upload/member")
]
我的问题是我无法读取从FormData 传递到 Laravel 的数据,即使这样:
return Response::json(['data' => $_POST['title']]);
或
return Response::json(['data' => Input::get['title']]);
将返回undefined index 'title',我的代码的哪一部分是错误的?感谢您的帮助。
【问题讨论】:
-
您是否尝试过通过以下方式转储所有输入数据:dd(Input::all());我注意到你在你的问题中使用了 Input::get['title'],这无论如何都行不通
标签: javascript php angularjs coffeescript laravel-4