I've been working on sending data to an API using Angular's $resource
. Currently, I can successfully retrieve data from my test server using a GET
request or querying. However, I'm having trouble figuring out how to send new data to the server using a POST
request. I have adapted the following code from the AngularJS documentation:
.factory("ResourceTest", function($resource) {
return $resource("http://mywebsite.com/api/:id", {id:'1'}, {
charge: {method:'POST', params:{charge:true}}
});
});
When I use ResourceTest.charge();
in my controller, everything works fine and I can see the POST
request in the server logs. However, when I try to pass any parameters with the function call (e.g.
ResourceTest.charge({test:false});
), the request does not go through and nothing appears in the logs. This issue also occurs with the .save()
method.
Could it be that there is a mistake in the code that I'm missing? I am relatively new to AngularJS and would appreciate any insights. Thank you!