Не могу отправить данные на сервер
Не могу понять причину.
Отправляю через POST App.prototype.sending = function (data, url) { var param = "data=" + data, xhr = new window.XMLHttpRequest(); xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { alert(xhr.responseText); } }; xhr.send(param); }; |
тоже самое, через GET - работает:
App.prototype.sending = function (data) { var param = "?data=" + data, xhr = new window.XMLHttpRequest(); xhr.open("GET", this.url + param, true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { alert(xhr.responseText); } }; xhr.send(null); }; |
dmitry111, ты выставляешь неверный Content-Type. Правильно так:
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
Часовой пояс GMT +3, время: 06:52. |