I'm attempting to make function that will send html code to this api(https://www.10bestdesign.com/dirtymarkup/docs) to format it cleanly. I have tried sending it different types data but I always get status 200 and responseText is empty html.
My function:
function cleanData(){
var url = "https://www.10bestdesign.com/dirtymarkup/api/html";
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.log("Error", xhr.statusText);
}
}};
var data = JSON.stringify({
"code": html_element.outerHTML,
"indent": 2
});
console.log(data);
xhr.send(data);
}
responseText:
{
"clean": "<!DOCTYPE html>\n<html>\n<head>\n <title></title>\n</head>\n<body>\n undefined\n</body>\n</html>"
}
This is always the responseText. xhr status is always 200 no matter what I send and it never contains any of the code sent to be cleaned/formatted.
I've tried sending different data to the api but I always get the same response.