I am trying to find a best way to update the file on the server with new elements. I tried looking into http post/put but I am getting an error and not sure exactly how to get this fixed. My http get method is working fine, so it's not an environment issue.
based on the comments here is the addition information and I have corrected the json file format as well.
Development environment: Visual Studio 2013, .net 4.5, iis
json data file sits on one of the folders under Visual studio solution. However I am only using angular features to develop this one page app, so no asp.net features in my code so far. I had to add to access the json file in the solution.
I have a simple car app for owners which loads from following array from file source using http get:
owners: [{
"name": "name1",
"age": 29,
"cars": [
{
"carmodel": "tyota",
"make": 2000
},
{
"carmodel": "ford",
"make": 2001
}
]
},
{
"name": "person1",
"age": 50,
"cars": [
{
"carmodel": "ford",
"make": 2011
}
]
}
]
from UI I am getting a new car object for say "person1"
car: {
"carmodel": "BMW",
"make": 2015
}
I would like to add this to the file using httppost or any other best practice method.
I have a save function which throws post error: 405 (Method Not Allowed)
$scope.save = function(owner, car, $http)
{
$scope.owners[1].cars.push(car);
// above is hard coded, how can filter owners with owner object?
$http.post('url',$scope.owners);
}
I am wondering what is the best practice update file on server. any help on this would be grateful.