AngularJS $ http.post 404

编程入门 行业动态 更新时间:2024-10-11 11:20:16
本文介绍了AngularJS $ http.post 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想测试一下$ 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

本文发布于:2023-10-10 09:43:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478319.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:http   AngularJS   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!