A
A
Alexander2020-02-04 13:43:20
JavaScript
Alexander, 2020-02-04 13:43:20

How to send object in POST on axios?

And Vue is here despite that from it. But it doesn't really matter.

The question is the following - I have an object, let's say this:

var data = {
  'ITEMS': [
    {
      'id': 174,
      'params': {
        'param1': [7,12,44],
        'param2': 'sold'
      }
    },
    {
      'id': 219,
      'params': {
        'param1': [],
        'param3': 1237
      }
    },
  ],
  
  'DATE': '24.07.2016',
  'TIME': "10:22",
  
  'GEO': {
    'ADDRESS': 'Охотный ряд 2',
    'LONGITUDE': 0,
    'LATITUDE': 0,
  },
  'PAYSERVICE': 0,
  'VAT': false,
  'PRICE': 0,
  
  'MESSAGE': '',
  
  'AGENT': 1
}


And I need to send it with a POST request. And exactly as query variables, and not in its body.
Not in the form of json and not in the form of base64, a serialized object or something like that.
It is in the form of POST.
On the server side, I want to get the content of $_POST like this:
[
  'ITEMS' => [
    0 => [
      'id' => 174,
      'params' => [
        'param1' => [0 => 7, 1 => 12, 2 => 44],
        'param2' => 'sold'
      ]
    ],
// ....
// и так далее


How to do it?

UPD:
For those who are especially dumb - I know that for this I have to send urlencoded form data, I know that you can use the FormData object for this, I know that it does not work with Object and damn I know that I can write a recursive function that shoves my object into FormData using append, and then give this FormData to the axios input!
I'm asking if I can somehow pass an object to axios as input without first converting it, or using the built-in axios mechanism.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
M-ka, 2020-02-04
@M-ka

The link will provide a complete and detailed answer to this question.
Pysy:

  • well, at least sometimes open the documentation
  • Didn't find the right answer in the link ? in the link there is a link on the axios dock
  • Didn't find the right answer in the axios dock? question should be asked about the correctness of the question
  • not asking the right question? so why expect the right answer...
  • perhaps you should still flip through the mana about $ _POST

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question