Answer the question
In order to leave comments, you need to log in
Why does javascript ajax send an empty POST request?
Good afternoon everyone, I can’t understand why an empty request is sent if JSON data is sent, but if not JSON is sent, but, for example, in application/x-www-form-urlencoded encoding, then everything is fine. jQuery is not suggested.
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState==4) {
console.log(xhr.responseText);
}
}
xhr.open("POST", urli, false);
var json = JSON.stringify({ user_id: user, tag_id: tag }, null, '\t'); console.log(json); //Здесь JSON выводится в консоли нормально
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
xhr.send(json);
//Переменные user, tag, urli указаны, с этим проблем нет.
<?php
if (isset($_POST))
var_dump($_POST);
Answer the question
In order to leave comments, you need to log in
Maybe send to another domain? Cross-domain requests are difficult to support.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question