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

Sending a JavaScript array to PHP via POST - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. I am trying to send a JavaScript array to a PHP file via POST. More on stackoverflow.com
🌐 stackoverflow.com
April 23, 2017
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
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. ... If you want to pass a JavaScript object/hash (ie. an associative array in PHP) then you would do: More on stackoverflow.com
🌐 stackoverflow.com
November 11, 2011
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
🌐
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...
🌐
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.
🌐
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?

Find elsewhere
🌐
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 - After that, store the retrieved values into the userinfo table. Initialize a new array called $return_arr with the stored values, and return it in the JSON format. This will enable you to send ...
🌐
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.
🌐
Laracasts
laracasts.com › discuss › channels › laravel › how-to-send-array-from-script-to-controler
how to send array from script to controler
You should see 'tes' in the name column. Click on it to see a preview of the results ... <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>
🌐
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.
🌐
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.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Sending an array of objects in a node js post request - Curriculum Help - The freeCodeCamp Forum
November 22, 2024 - I am trying to send an array of objects in a post request but when I try to access the array with req.body it is just showing {object} and none of the objects content is being sent. Is there something wrong with my request? here is my request: Post http://localhost:3000/users/newOrder Content-Type: application/json { "firstName": "Craig", "lastName": "Mar", "address1": "10 a st", "address2": "apt 2", "email": "c@yahhoo.com", "town": "red bank",...