Answer the question
In order to leave comments, you need to log in
How to send html code from textarea to mongodb database?
// Это код который отправляет данные на сервер и сохраняет их в базе данных
async function sendToServer() {
const requestOptions = {
method: 'POST',
body: JSON.stringify({ ...form }),
headers: {
'Accept': 'application/json, text/html, */*',
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS"
}
};
const url = 'http://localhost:5000/api/news/add'
await fetch(url, requestOptions)
.then(res => res.json())
.then(res => alert('Новость успешно создана!'))
.catch(e => {
console.log(e)
})
return setForm({
title: '',
image: '',
descr: '',
shortDescr: '',
date: ''
})
}
// Это код модели в mongodb
const newsSchema = new Schema({
title: {
type: String,
default: 'Новость'
},
shortDescr: {
type: String,
required: true
},
descr: {
type: String,
required: true
},
image: {
type: String,
default: 'https://static8.depositphotos.com/1338574/829/i/600/depositphotos_8292496-stock-photo-news.jpg'
},
date: {
type: String
},
// imageDescr: {
// type: Array,
// }
})
(<b>Жирный шрифт</b>)
, I save this line in the database and also display it with tags on the page with this data
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question