0

I don't have a clue where to start to do this. I have a form in AngularJS, and I want it to append the data send through it to a json file. I know AngularJS it's just client-side, so my problem is on how to handle the data that the form is sending. The workflow i'm looking for is simply:

Angular Form -> Send through ¿POST? -> ??? -> Data added to file.json

What could I use to handle a POST from AngularJS?

1 Answer 1

2

You need a server backend like Node.JS, PHP, Python or Ruby etc.

The server will handle the HTTP post and in your case append the data to a json object.

It doesn't matter if you are using Angular or not, still its an HTTP POST :-)

In Node.JS + express.js 3 you can do

var express = require("express");
app.use(express.json());       // to support JSON-encoded bodies
app.use(express.urlencoded()); // to support URL-encoded bodies

So if you post {"name" : "john" , "surname" : "may"}

app.post('/MYPOSTLINK', function(req, res) {
    var name    = req.body.name;    // Get name from body of the incoming data
    var surname = req.body.surname; // Get surname from body of the incoming data
    res.send(200, {});              // what response to send back
    console.log("Your name is " + name + " " + surname);

});
Sign up to request clarification or add additional context in comments.

1 Comment

php would be almost perfect for that task. use file_get_contents, json_decode, add the data, the save the json_encode of modified array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.