I am new to angularJs, right now I want to use $http.put to update an Json file at a remote repository.
but everytime I try, I get the following error
XMLHttpRequest cannot load http://blabla&action=update.
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'localhost:9080' is therefore not allowed access.
So it doesn't work. now I did my part of search on Stack and google. a lot of people are saying I should add headers. I don't know how to add headers correctly and I have no idea how to verify if the headers are correctly added.
Can someone help me? The following is my code.
$http.defaults.headers.post['Access-Control-Allow-Origin'] = '*';
$http.defaults.headers.post['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PUT';
$http.defaults.headers.post['Access-Control-Allow-Credential'] = 'true';
$scope.update = function(key,value){
$scope.myData[key] = value;
$http.put('http://blabla&action=update', $scope.myData)
.success(function (data, status) {
alert('success');
})
the code above is still giving me the same error, from my research online, the headers are suppose to solve this problem... but it didn't. I don't know what I did wrong. thanks guys!