Adding AngularJS data to JSON file for update

I'm feeling lost on where to begin with this. I am working with an AngularJS form and I need it to add the data it sends to a json file. I understand that AngularJS is client-side, so my main issue lies in figuring out how to manage the data being sent by the form. The process I envision goes like this:

Angular Form -> Submit via POST method -> ??? -> Data appended to file.json

Is there a specific tool or technology I should utilize to handle a POST request from AngularJS?

Answer №1

To handle HTTP posts and append data to a JSON object, you will need a server backend such as Node.JS, PHP, Python, or Ruby.

Whether you are using Angular or not, the process remains an HTTP POST request.

In Node.JS with express.js 3, you can implement the following:

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

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

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

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The placement of Bootstrap Datepicker is experiencing issues

I have integrated the Bootstrap Datepicker from Eternicode into my ASP.Net MVC website. While the functionality is working well, I am facing difficulty in positioning the datepicker modal using the orientation option mentioned in the documentation and code ...

Using AngularJS to filter JSON data

Greetings! I possess the following JSON data: $scope.Facilities= [ { Name: "-Select-", Value: 0, RegionNumber: 0 }, { Name: "Facility1", Value: 1, RegionNumber: 1 }, { Name: ...

To manipulate the array in a more complex manner, either add or remove the item based on its existence: if it's already in the array, remove it; if it

As I prepare to send key-value pairs to the backend in the form of a JSON structure, each representing a category (e.g., customer churn rate), I encounter an issue. The idea is to add checkmarked options to the array of their respective categories. However ...

`Must have content in file input in order to be saved to MongoDB`

When attempting to save a registry in MongoDB using Node.js, it seems that the operation fails if an image is not selected. I would like the inclusion of an image in this process to be optional, rather than mandatory. router.post("/", upload.single("image" ...

The property 'dateClick' is not found in the 'CalendarOptions' type in version 6 of fullcalendar

Below is the Angular code snippet I am currently using: calendarOptions: CalendarOptions = { plugins: [ dayGridPlugin, timeGridPlugin, listPlugin ], initialView: 'dayGridMonth', headerToolbar: { left: 'prev today next' ...

Welcome to the launch of OpenWeatherMap!

I just signed up for an account on the OpenWeatherMap website. My goal is to retrieve the current weather information for a specific location using the City ID API Call: http://api.openweathermap.org/data/2.5/weather?id=2172797&appid=myAPIKey How ca ...

Is there a way to execute a JavaScript function by clicking on an anchor tag?

Many websites, such as StackOverflow, have attempted to address this particular issue. However, the explanations provided are complex and difficult for me to grasp. I am looking for someone who can help identify my mistakes and explain the solution in simp ...

What could be causing Jquery to not function properly in an Angular controller?

Can someone please help me understand why my code is not working in JSFiddle? Any assistance would be appreciated! UPDATE: I have to admit, the negative feedback is disheartening. I may not know everything, but asking questions is how we learn. What' ...

Tips for retrieving the posted object in angularJS

My current challenge involves creating an object with a defined name, posting it into a database, and then immediately finding its position and obtaining its id. However, I have noticed that using "get" right after "post" retrieves the data before it' ...

Tips for generating a node for the activator attribute within Vuetify?

Vuetify offers the 'activator' prop in multiple components like 'v-menu' and 'v-dialog', but there is limited information on how to create a node for it to function correctly. The documentation states: Designate a custom act ...

Display the div only when the radio button has been selected

I have been attempting to tackle this issue for quite some time now, but unfortunately, I haven't had any success. My goal is to display a specific div on the webpage when a particular radio button is selected. While I have managed to achieve this by ...

Sharing data between components using $state.params and $stateParams

I have gone through several articles but none of them seem to be effective: I am trying to send some information using $state.go. This is the state configuration: .state('app.404', { url: '404', views: { 'header@&ap ...

Unable to locate views in Angular-route

Within my angular app-file, I am configuring the routing as follows: (function() { var app = angular.module("CustCMS", ["ngRoute"]); app.config(function ($routeProvider) { $routeProvider .when("/Index", { templateUrl: "~/CustCMS/V ...

What is the best way to access Dynamic Array Data within a nested ng-repeat loop?

Dealing with JSON data that is deeply nested with strings and arrays, I am attempting to assign a true or false value for each day. Below is how I achieved this without a nested array: No Nested Array(Codepen 1) Here's the HTML: <ion-toggle ng-r ...

Which Restlet(Java) libraries are required for performing JSON GET and POST requests?

This question seems to be a repeat of one asked back in 2010, which you can find here. However, considering it's now 2017 and things may have changed, I believe it's worth revisiting this topic. Which libraries are necessary? With the use of ...

The initial JSON array is displaying correctly, however the subsequent nested arrays are appearing as [Object, object]

I am currently utilizing a wordnik API to gather the word of the day and extract array information. However, I am encountering an issue where the nested arrays are displaying as "object, object" rather than the expected data <script src="https://ajax ...

What is the best way to clear and fill a div without causing it to resize?

I am faced with a challenge involving four thumbnail divs labeled .jobs within a #job-wrap container. When a .job is clicked, I want the #job-wrap to fade out, clear its contents, load information from the selected .job, and then fade back in. However, whe ...

Simulated FileList for Angular 5 App Unit Testing

Imitation FileList In my pursuit of writing a unit test (Angular5), I have encountered the need for a FileList. Despite researching extensively, I have been unable to uncover any clues or solutions. I am starting to question whether this is even feasible ...

Retrieving value from the parent scope using the conventional approach

Today I was puzzled by some unexpected behavior of AngularJS. While using console.log to log $scope, I noticed that there was no key attached to the scope named val1. However, when I used console.log($scope.val1), it returned a value as an object. After ...

Attempting to send a Promise to another function for it to return, encountering an error of "Unhandled promise rejection"

My goal is to develop a versatile database update function that can be utilized for creating more customized update functions. Within the module database.js, the following code is present: const {Pool,Client}=require('pg'); const pool=new Pool( ...