$scope.submitBracket = function(item, event){
console.log("submitting form");
var jsonData = '{"userEmail" : "darwood@mail.com","brackets" :' + JSON.stringify($scope.allGames) + '}';
var testJSON = {"Hello": {"id": "file", "value": "WTF"}};
console.log(jsonData);
var responsePromise = $http.post("/api/brackets", jsonData, {});
responsePromise.success(function(dataFromServer,status,headers,config){
console.log(dataFromServer);
});
responsePromise.error(function(data,status,headers,config){
console.log(data);
});
}
I am working on a MEAN stack app which has a form submitting a JSON object to MongoDB. the JSON is valid. It can be submitted to the database manually with no problems. In the above code example I can see the object being output to the console right before being sent to the db via an HTTP post that is the handed off to an express route. Oddly, I had it working and then in testing removed the records from the db to enter new ones and it started submitting a JSON object with an empty array. Sometimes it throws an "empty response message but the POST request does get a 200 response back. I can't for the life of me figure out why the data is not being passed.
If also tried this alternative function on the Angular side to send the data:
$scope.createBracket = function() {
var jsonData = '{"userEmail" : "darwood@mail.com","brackets" :' + JSON.stringify($scope.allGames) + '}';
$http.post('/api/brackets', jsonData)
.success(function(data) {
$scope.brackets = data;
$location.path('/');
})
.error(function(data) {
console.log('Error: ' + data);
});
};
This is the express route that it is passed off to.
app.post('/api/brackets', function(req, res) {
// create a Bracket
Bracket.create({
text : req.body.text,
done : false
}, function(err, Bracket) {
if (err)
res.send(err);
});
});
when using Postman to test with raw JSON. It hangs for a long time and says that the request is pending. This code was modeled after the tutorial found here
http://scotch.io/tutorials/javascript/creating-a-single-page-todo-app-with-node-and-angular
I have this sample code up and running and inserting into my database with no problem.
Stumped I am. Any help would be appreciated. Thanks.