async send_Data_to_Api() {
//------<
send_Data_to_Api() >------
console.log(this.state);
//< get
text >
let element =
document.getElementById('ctleditor_html');
let editor_innerhtml =
element.innerHTML;
let text_of_htmleditor =
element.innerText;
//</
get text >
//--<
prepare send >--
const requestOptions = {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(
{
//< data to send >
idarticle: this.state.idarticle,
iduser: this.state.iduser,
title: this.state.title,
htmlcontent:
editor_innerhtml,
textcontent:
text_of_htmleditor,
folder: this.state.folder,
keywords: this.state.keywords,
//</ data to send >
})
};
//--</
prepare send >--
//<
send >
const response = await fetch('api/articles/' + this.state.idarticle, requestOptions); //*SEND DATA
//</
send >
if (response.status !== 200) {
//-< error: sending >-
if (response.status === 400) alert("Bad Data Request");
else if (response.status === 403) alert("User is not Owner");
else alert('send error');
//-</ error: sending >-
}
else {
//-< ok: sending result >-
const data = await response.json();
//*refresh return values
this.setState({
idarticle: data.idArticle,
iduser: data.idUser,
title: data.title,
htmlcontent:
data.htmlcontent,
folder: data.folder,
keywords: data.keywords,
loading: false,
status: "data ok"
});
//-</ ok: sending result >-
}
//------</
send_Data_to_Api() >------
}
|