Answer the question
In order to leave comments, you need to log in
How to send a JSON object to a foreign API using the GET method from JS?
You need to get data from the transport company. Their documentation says
To get the cost and delivery time, you need to send a json object to the CDEK server. When passing a json object, the appropriate Content-Type must be specified in the header.
api.cdek.ru/calculator/calculate_price_by_json.php
Content-Type: application/json
api.cdek.ru/calculator/calculate_price_by_jsonp.php
dataType : "jsonp" (from js)
api.cdek.ru/calculator/calculate_price_by_json_req...
Content-Type: application/x-www-form-urlencoded
Answer the question
In order to leave comments, you need to log in
XMLHttpRequest.setRequestHeader()
Using Fetch: Supplying Request Parameters
var xhr = new XMLHttpRequest();
xhr.open('GET', '/server', true);
xhr.onload = function () {
// Запрос завершен. Здесь можно обрабатывать результат.
};
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send({ form: 'data' });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question