G
G
Gimir2018-05-11 19:56:17
Python
Gimir, 2018-05-11 19:56:17

How to send array or dictionary in XMLHttpRequest with JS in Python?

Good day!
Here is the code:

document.querySelector('#rateForm').onsubmit = () => {
                      const xhr = new XMLHttpRequest();
                      var rate = document.querySelector('#rate').value;
                      var text = document.querySelector('#text').value;

                      word = {"rate": rate, "text": text, "isbn": isbn}

                      const currency = word;
                      xhr.open('POST', '/comment', true);

                      xhr.onload = () => {
                        const data = JSON.parse(xhr.responseText);

                        console.log(data)

                      }

                      const data = new FormData();
                      data.append('currency', currency);
                      console.log(currency)
                      xhr.send(data);
                      return false;

                    };


Please explain how to make a request correctly so that the data reaches the server. In this example, my server simply accepts an object, but there is no data in it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question