将数据发布到 JSON - Angular .post
Posting data to JSON - Angular .post
我正在处理一个应用程序,但发布到资产中的.JSON
文件时遇到问题。 我正在使用基于Angular
的应用程序。 我收到的错误代码404
响应为:Cannot POST /assets/data/card-stack.json
. 现在的问题是,当我使用get
来检索JSON
数据时,它的效果很好。 只有当我使用.post
. 这是我正在做的事情:
$http.get('./../../assets/data/card-stack.json').success(function(data) {
$scope.cards = data;
// Set the showdown images from the card data grabbed from the card-stack.json file
$scope.showdowns = [
$scope.cards[0].url,
$scope.cards[1].url,
$scope.cards[2].url,
$scope.cards[3].url
];
});
// Simple POST request example (passing data) :
$http.post('./../../assets/data/card-stack.json', {url : './../images/banana.jpg'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
console.log(data);
// called asynchronously if an error occurs
// or server returns response with an error status.
});
建议?
.
json文件是一个静态文件,只包含json数据,因此您将无法发布到该文件。相反,您需要使用服务器端页面或服务(如 php)来处理发布的数据。
尝试设置 $http 标头:
$http.defaults.headers.post["Content-Type"] = "application/json";
试试吧。
相关文章:
- 可以't通过Angular$resource POST数据
- Angular JS `$http`发送POST而不是GET
- 在Angular JS中POST后重新加载指令方法
- 如何将多个onError函数分配给promise(由angular's$http.post返回)
- 从 Angular 数据工厂中的 HTTP POST 请求接收未定义的结果
- 对php的Angular post请求失败
- 无法读取属性'用户名'对于Angular Post Request,共个未定义
- 将数据发布到 JSON - Angular .post
- 如何基于 stdout 和 stderr 验证来自 nodejs 的 angular post 调用
- 从angular post方法获取数据
- 在Angular post请求之前删除字段中的空白
- 不能使用Angular POST数据到Laravel 5控制器,Error: 422 Unprocessable Ent
- 处理Angular POST中的快速重定向
- 在angular-POST请求中承诺
- Angular POST JSON structure
- Angular POST to Node Server
- Angular POST request
- 使用Angular$post和PHP Codeigniter进行请求和响应
- Angular Post函数没有执行的动作
- 我如何将数据从angular post传递到web api post