【发布时间】:2014-11-15 09:19:50
【问题描述】:
我正在尝试在 Laravel 4 和 Angular JS 中开发我的应用程序,我的应用程序允许用户通过文本更改通过系统检索他们的信息。
Angular 用于将用户输入的数据传递给 Laravel,然后 Laravel 从数据库中检索信息。
但是 Laravel 无法检索从 Angular 传递的数据。
查看
<div data-ng-controller="ReservationController">
<input id='ERI' type='text' data-ng-model="scanRID" data-ng-change="queryRes()" name='exampleInput' maxlength='3' />
</div>
角工厂
app.factory('exampleFactory', function($http) {
var factory = {};
factory.getExample = function(scanRID) {
return $http({
method: 'GET',
url: LARAVEL_CONTROLLER + 'Example',
data: $.param(scanRID)
});
};
return factory;
});
角度控制器
app.controller('exampleController', function($scope, $http, exampleFactory) {
$scope.queryRes = function() {
if($scope.scanRID.length == 3) {
exampleFactory.getExample($scope.scanRID)
.success(function (data) {
// Do Something Here
})
.error(function (data) {
console.log(data);
});
}
};
});
Laravel 4 条路线
Route::get('Example', 'ExampleController@show');
Laravel 4 示例控制器
class ExampleController extends \BaseController {
public function show()
{
$id = Input::get('scanRID'); // This here might be wrong. It's always empty!
$data = ExampleModel::find($id); // Able to query and retrieve.
return Response::JSON($data); // Returns empty.
}
}
Laravel 4 示例模型
class ExampleModel extends Eloquent {
// The id of this table is what I want, but I can't retrieve it.
protected $fillable = ['id', 'ExampleData1', 'ExampleData2'];
protected $table = 'exampleTable';
}
我到处寻找解决方案,似乎每个人都能够成功地进行Ajax调用。我认为我错过了一些我不知道的东西。
我也尝试过设置 CSRF Token,但是,我认为这不是问题。所以我最后的办法是求助于专家,希望有人能够帮助我。
附带说明,我对 Laravel 和 Angular 还很陌生,所以如果您确实发布了解决方案,请向我解释这个问题,因为我想了解更多关于 Angular 和 Laravel 的信息。
感谢您查看我的问题。
【问题讨论】:
标签: javascript php ajax angularjs laravel-4