问题描述
我想测试一下$ http.post发布数据到服务器。后端是建立与laravel。
I'm trying to test posting data to the server using $http.post. The backend is built with laravel.
我刚学角度,所以没有什么复杂的事情。当我尝试发布到/ API和我在浏览器控制台得到一个404错误。如果我在浏览器中打开URL它确实存在。该页面本身只是返回一些JSON。
I'm just learning Angular so there isn't anything complicated going on. When I try to post to /api and I get a 404 error in my browser console. If I open the URl in a browser it does exist. The page itself just returns some json.
这里是HTML:
<ul>
<li ng-repeat="brand in brands">
<input type="checkbox" name="{{brand.brand_name}}" ng-model="brand.checked" ng-change="getSelectedBrands()">
{{ brand.brand_name }}
</li>
</ul>
和控制器的部分负责发布数据
And the part of the controller responsible for posting the data:
$scope.getSelectedBrands = function() {
var data = $filter('filter')($scope.brands, {checked: true});
$http.post('/api', data).success(function(data, status, headers) {
//do something
});
}
为什么在每一个复选框选中或取消选中职位是这些复选框将被过滤数据库中的结果,一旦我得到那个阶段。
Why it posts on every checkbox check or uncheck is that these checkboxes will be filtering results from the database once I get to that stage.
任何帮助将大大AP preciated。
Any help would be greatly appreciated.
谢谢!
随着网络TAB RESULT编辑:
EDIT WITH NETWORK TAB RESULT:
推荐答案
如果您在浏览器中打开URI您正在执行一个GET请求。有可能你的后端设置响应GET的路线,但无法发布。
If you open the URI in a browser you are performing a GET request. It's possible your backend is setup to respond to GET routes but not POST.
这篇关于AngularJS $ http.post 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!