Document
You have less than 5 characters!
You have more than 5 characters!
twitter.com/{{ lowercasehandle() }}
Rules
-
{{ rule.RuleName }}
Add rule: Add
//app.js
var myApp = angular.module('myApp', []);
myApp.controller('mainController', ['$scope', '$filter','$http',function ($scope, $filter,$http) {
$scope.handle = '';
$scope.characters = 5;
$scope.lowercasehandle = function () {
return $filter('lowercase')($scope.handle);
}
$http.get('/angularjs/http/api.json')
.success(function(result){
$scope.rules = result;
})
.error(function (data,status) {
console.log(data);
})
$scope.newRule = '';
$scope.addRule = function () {
$http.post('/angularjs/http/api', { newRule: $scope.newRule })
.success(function (result) {
console.log(result);
$scope.rules = result;
$scope.newRule = '';
})
.error(function (data, status) {
console.log(data);
});
};
}]);
//api.json
[
{
"ID":1,
"RuleName":"Must be 5 characters"
},{
"ID":2,
"RuleName":"Must be 5 characters"
},{
"ID":3,
"RuleName":"Must be 5 characters"
}
]
能get到数据,但是post的时候没有更新json数据,和Accept:application/json, text/plain, */* 这个有关吗?该怎么解决。。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
get的时候随便一个本地的服务器或者不用服务器直接读取json文件就能得到数据。但是如果你想把页面上更改的内容保存回去,就需要服务端代码来处理,angular 本身的$http是没有进行文件写入的功能的。
想保存数据的话,post的接口需要有对应的代码逻辑进行文件操作才行。贴后端处理json数据的代码吧,骚年!