Есть простой текстовый веб-редактор. Из него необходимо передать данные на сервер в базу данных, но проблема в том, что на сервер приходят обрезанные данные. Вот данные для отправки:
data={"header":"header","content":"<div style=\"margin: 0px 14.3906px 0px 28.7969px; padding: 0px; width: 436.797px; float: left; font-family: "Open Sans", Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);\"><h2 style=\"margin: 0px 0px 10px; padding: 0px; font-weight: 400; line-height: 24px; font-family: DauphinPlain; font-size: 24px;\">What is Lorem Ipsum?</h2><p style=\"margin: 0px 0px 15px; padding: 0px; text-align: justify;\"><strong style=\"margin: 0px; padding: 0px;\">Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></div><br><div style=\"margin: 0px 14.3906px 0px 28.7969px; padding: 0px; width: 436.797px; float: left; font-family: "Open Sans", Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);\"><div><br></div></div>"}&table=news
В переменной data лежит JSON, в котором заголовок и содержимое, но на сервер из data приходит только это:
{"header":"header","content":"<div style=\"margin: 0px 14.3906px 0px 28.7969px; padding: 0px; width: 436.797px; float: left; font-family:
Как правильно отправить HTML через POST?
Данные отправляются через XMLHttpRequest:
function xmlHTTPconnect(scenario, data, callback){
var xml = new XMLHttpRequest();
xml.open("POST", scenario, false);
xml.setRequestHeader('Content-type', "application/x-www-form-urlencoded; charset=utf-8");
xml.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
callback(this.responseText);
}
}
xml.send(data);
}
Со страницы выглядит так:
xmlHTTPconnect("../php/db_insert.php", data, console.log)
На сервере просто получаются данные из data:
$data = strval($_POST["data"]);
И формируется JSON
$dataJSON = json_decode($data, true);