I'm assuming you're making a POST request with a JSON payload. First, you want to make sure your payload is formatted JSON correctly, use: http://pro.jsonlint.com/

Secondly, you can send the payload using JSON.stringify and you will want to set the contentType:

data: JSON.stringify(data), contentType: "application/json; charset=utf-8"

If you run this and look at your network tab in Dev Tools in Chrome, it will error out, but you will at least see the payload formatted to send to the server: http://prntscr.com/f8hf6s

var data = [{
    "key": "myKey",
    "keyName": "myKeyName",
    "value": "value",
    "valueName": "valueName"
  },
  {
    "key": "mySecondKey",
    "keyName": "mySecondKeyName",
    "value": "secondValue",
    "valueName": "secondValueName"
  }
];

var url = "http://swapi.co/api/";

$.ajax({
  type: "POST",
  url: url,
  data: JSON.stringify(data),
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  error: function() {
    alert("Error");
  },
  success: function() {
    alert("OK");
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Answer from Woodrow on Stack Overflow
Discussions

How to pass a Javascript Array via JQuery Post so that all its contents are accessible via the PHP $_POST array? - Stack Overflow
How can I pass a Javascript Array via JQuery Post so that all its contents are accessible via the PHP $_POST array? Please show an example of code that would do the trick. Thanks! More on stackoverflow.com
🌐 stackoverflow.com
July 4, 2011
What is the "best practice" for sending an array of objects to the server?
Assemble the array in your front end, attach the json to your form data and post it. More on reddit.com
🌐 r/webdev
22
17
November 3, 2023
Send an array of JavaScript objects via POST - Stack Overflow
I have an array of objects that I am trying to send to my PHP script. Before sending the array I can access all the data in it and everything is there. Once it gets to PHP var_dump returns NULL. I'... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Send Array in post request using node.js using application/x-www-form-urlencoded - Stack Overflow
I tried to send post request to API and the post parameters should be array, this is how to send it in cURL curl http://localhost:3000/check_amounts -d amounts[]=15 \ -d amounts[]=30 I tried t... More on stackoverflow.com
🌐 stackoverflow.com
April 1, 2015
🌐
Reddit
reddit.com › r/webdev › what is the "best practice" for sending an array of objects to the server?
r/webdev on Reddit: What is the "best practice" for sending an array of objects to the server?
November 3, 2023 -

Short backstory: I learned Angular straight out of uni and thought it might be useful to get some basic knowledge about how the web works on a fundamental level. So I decided to build a small MPA with Go as a backend language.

Now I got to a problem that would be trivial to solve in Angular but I am having trouble solving with server-side rendering:

Imagine a traditional form where I can add and remove items (kind of like a shopping cart) with javascript and once I am done I can click on "Save" and all items are send to the server with a POST request. The special thing is that the items are complex objects with multiple properties, not just strings.

I would prefer to use a form and just submit it, but it feels like this type of complex data does not go well with a form. I know that PHP can handle this kind of structure (https://stackoverflow.com/questions/34313657/html-form-post-an-array-of-objects), but I don't think this is standard, since there doesn't seem to be a way to do this in Go. So is my only choice to send JSON? But how do I transform my input values to JSON?

So the question is this: what is the best practice when I need to send an array of objects to the server and how would a person have solved this 10 or 15 years ago?

🌐
Makitweb
makitweb.com › home › ajax › how to send javascript array to the ajax using jquery and php
How to Send JavaScript Array to the AJAX using jQuery and PHP - Makitweb
December 21, 2023 - Note – You can pass JavaScript Array variable as same as any other variable in AJAX request. $(document).ready(function(){ // submit button click $("#submit").click(function(){ var name = $("#txt_name").val(); var email = $("#txt_email").val(); ...
🌐
Quora
quora.com › How-do-I-send-a-JSON-array-in-a-post-request
How to send a JSON array in a post request - Quora
Answer (1 of 4): What you need to do is to proceed with these steps: 1. Create the JSON Array: First, you need to create the JSON array that you want to send in your POST request. Make sure the data is properly formatted as a valid JSON array. 2. Set Headers: In your POST request, you'll need to...
Find elsewhere
🌐
Laracasts
laracasts.com › discuss › channels › laravel › how-to-send-array-from-script-to-controler
how to send array from script to controler
<script type="text/javascript"> function sendData() { var data = [ 1, 2, 3 ]; $.ajax({ url:'/test', type: 'POST', dataType:'json', contentType: 'json', data: JSON.stringify(data), contentType: 'application/json; charset=utf-8', }); } </script> in controller · function saveJson(Illuminate\Http\Request $request) { $data = json_decode($request->getContent()); } in app\Http\Middleware\VerifyCsfrToken ·
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 197159 › how-do-i-pass-arrays-in-javascript-to-php-using-post-method
how do i pass arrays in javascript to php using POST method
June 12, 2009 - The good news for non-json folks is that standard javascript is also very compact for an indexed array comprising numbers or strings or a mixture of the … — Airshow 425 Jump to Post · ok I saw this on another page. so I am not sure how it will work. but as a data when you send arrayElement=1&arrayElement=2&arrayElement=3 you can send all the elements to server.
🌐
Quora
quora.com › Whats-the-best-way-to-send-an-array-of-JavaScript-objects-to-serverside-running-PHP-using-jQuery
What's the best way to send an array of JavaScript objects to serverside (running PHP) using jQuery? - Quora
Answer (1 of 6): Sounds like you should just pass the data as part of your form request. Possibly by converting it to a JSON string and writing it to a hidden field using $('#yourhiddenfieldid').val(yourString) and then processing it on the backend as part of the account creation process.
🌐
Coderwall
coderwall.com › p › ywtneg › pass-array-through-post-method
Pass array through POST method (Example)
January 4, 2021 - How to pass an array using POST method. First use the function json_encode() to encode the array. Then use htmlspecialchars() to avoid errors caused by the quotes in json.
🌐
ReqBin
reqbin.com › code › javascript › wzp2hxwh › javascript-post-request-example
How do I send a POST request using JavaScript?
November 24, 2023 - To make an HTTP POST request from a web browser, JavaScript offers two primary methods: the promise-driven fetch() API and the callback-driven XMLHttpRequest object. To send POST requests from Node.js, you can use the native "http" module. To make a POST request with JavaScript Fetch API, you must indicate the HTTP POST method name with the "method" parameter and the POST payload in the "body" parameter.
🌐
Bubble
forum.bubble.io › need help › apis
POST Request: dynamically send an array (list) in a JSON - APIs - Bubble Forum
February 7, 2022 - Hey everyone, I need to send a POST Request to an API. This post request contains a field “envs”, which contains an array of objects (each of those contains a “key” and a “value” - both strings) (See screenshot). I cannot simply hardcode this information into the request.
🌐
GitHub
github.com › axios › axios › issues › 4394
How to send array of object in post request using axios library · Issue #4394 · axios/axios
January 17, 2022 - }) console.log(ytVideosList) //showing data inside array console.log(ytVideosList.length) // this shows as zero strange ... The problem is that map function with async and await which make "ytVideosList.push(video)" execute after "console.log". May be you should write like this: ` const ytVideosList = [] const GetVideos = await axios.post(...); const ytIDs = GetVideos.data; const requestList = ytIDs.map(item => youtube.getVideo(item)); const arr = await Promise.all(requestList);// arr is the list you need ytVideosList = arr;// you can handle the data with your business // your another call API