Angularjs laravel 5 使用发布方法 404 页面未找到错误发布表单数据.但是获取方法有效



使用 Angularjs laravel 5.1 使用发布方法 404 发布表单数据错误来了 但是获取方法工作正常

控制器

(function (ng, app) {
app.controller('app.promocodeCtrl', function ($scope, $http) {
// create a message to display in our view
$scope.newPromocode = function () {
$scope.onSubmit = function () {
console.log($scope.form);
// $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
//$http.defaults.headers.post["Content-Type"] = "text/plain";
var request = $http({
method: "POST",
url: "backend/statistics/promo",
data: {
promocode: $scope.form.codetxt,
discount: $scope.form.discount,
minvalue: $scope.form.minvalue
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).success(function (data) {
alert(data);
});
}
};
});
})(angular, angular.module('app'));

路线

Route::post('statistics/promo', ['uses' => 'ApiBackendStatistics@promoCode']);

确保 Angular 使用的 url 和后端的路由定义相同。看来 Angular 中使用的 url 在 laravel 中没有被定义为正确的路由。/api/backend 或/backend 尝试在浏览器中点击角度 URL,并检查您得到的响应。

最新更新