I have such a problem that I can’t edit columns in the database through api, everything else works, creating, deleting, etc., but there are no changes in the logs, there are no errors, maybe there is a syntax error somewhere, or I forgot to add something
the code itself works, I misclicked somewhere and now I can’t find where help please abobaPost is responsible for the change edit post
let id = null;
async function getPosts() {
try {
let res = await fetch('http://api.ru/posts');
if (!res.ok) {
throw new Error('Error fetching posts');
}
let posts = await res.json();
let postListElement = document.querySelector('.post-list');
document.querySelector ('.post-list').innerHTML = '';
posts.forEach((post) => {
document.querySelector ('.post-list').innerHTML += `
<div class="card" style="...">
<div class="card-body">
<h5 class="card-title">${post.brand}</h5>
<h6 class="card-subtitle">${post.model}</h6>
<p class="card-text">Body Color: ${post.bodycolor}</p>
<p class="card-text">Status: ${post.Status}</p>
<p class="card-text">State Number: ${post.StatenumberoftheRussianFederation}</p>
<a href="#" class="card-link">Read More</a>
<a href="#" class="card-link" onclick="removePost(${post.id})">Удалить</a>
<a href="#" class="card-link" onclick="editPost('${post.id}', '${post.brand}', '${post.model}', '${post.bodycolor}', '${post.Status}')">Редактировать</a>
</div>
</div>`;
});
} catch (error) {
console.error(error);
}
}
async function addPost() {
const brandInput = document.getElementById('brandInput').value;
const modelInput = document.getElementById('modelInput').value;
const bodycolorInput = document.getElementById('bodycolorInput').value;
const stateNumberInput = document.getElementById('stateNumberInput').value;
const statusInput = document.getElementById('statusInput').value;
let formData = new FormData();
formData.append('brand', brandInput);
formData.append('bodycolor', bodycolorInput);
formData.append('model', modelInput);
formData.append('stateNumber', stateNumberInput);
formData.append('status', statusInput);
const res = await fetch('http://api.ru/posts', {
method: 'POST',
body: formData
});
const data = await res.json();
console.log(data);
if (data.status === true) {
await getPosts();
}
}
async function removePost(id) {
const res = await fetch(`http://api.ru/posts/${id}`, {
method: "DELETE"
});
const data = await res.json();
if (data.status === true) {
await getPosts();
}
}
function editPost(id, brand, bodycolor, model, status) {
document.getElementById('brand-Input').value = brand;
document.getElementById('model-Input').value = model;
document.getElementById('bodycolor-Input').value = bodycolor;
document.getElementById('status-Input').value = status;
}
async function abobaPost(id) {
const brand = document.getElementById('brand-Input').value;
const model = document.getElementById('model-Input').value;
const bodycolor = document.getElementById('bodycolor-Input').value;
const status = document.getElementById('status-Input').value;
const data = {
brand: brand,
model: model,
bodycolor: bodycolor,
status: status
};
const res = await fetch(`http://api.ru/posts/${id}`, {
method: "PATCH",
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
});
let resData = await res.json();
if (resData.status === true) {
await getPosts();
}
}
getPosts();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My blog</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
<div class="container mt-5">
<div class="row post-list"></div> <!-- Контейнер для карточек постов -->
<div class="row col-12">
<div class="form-group col-6">
<label for="brandInput">Бренд</label>
<input type="text" class="form-control" id="brandInput" aria-describedby="brandHelp">
</div>
<div class="form-group col-6">
<label for="modelInput">Модель</label>
<input type="text" class="form-control" id="modelInput" aria-describedby="modelHelp">
</div>
<div class="form-group col-6">
<label for="bodycolorInput">Цвет кузова</label>
<input type="text" class="form-control" id="bodycolorInput" aria-describedby="bodycolorHelp">
</div>
<div class="form-group col-6">
<label for="stateNumberInput">Государственный номер</label>
<input type="text" class="form-control" id="stateNumberInput" aria-describedby="stateNumberHelp">
</div>
<div class="form-group col-6">
<label for="statusInput">Статус</label>
<input type="text" class="form-control" id="statusInput" aria-describedby="statusHelp">
</div>
</div>
<div class="row col-12 mt-2">
<div>
<button class="btn btn-primary" onclick="addPost()">Добавить пост</button>
</div>
<div class="row col-12">
<div class="form-group col-6">
<label for="brandInput">Бренд</label>
<input type="text" class="form-control" id="brand-Input" aria-describedby="brandHelp">
</div>
<div class="form-group col-6">
<label for="modelInput">Модель</label>
<input type="text" class="form-control" id="model-Input" aria-describedby="modelHelp">
</div>
<div class="form-group col-6">
<label for="bodycolorInput">Цвет кузова</label>
<input type="text" class="form-control" id="bodycolor-Input" aria-describedby="bodycolorHelp">
</div>
<div class="form-group col-6">
<label for="stateNumberInput">Государственный номер</label>
<input type="text" class="form-control" id="state-NumberInput" aria-describedby="stateNumberHelp">
</div>
<div class="form-group col-6">
<label for="statusInput">Статус</label>
<input type="text" class="form-control" id="status-Input" aria-describedby="statusHelp">
</div>
</div>
<div class="row col-12 mt-2">
<div>
<button class="btn btn-primary" onclick="abobaPost()">Редактировать пост</button>
</div>
</div>
</div>
<script src="js/may.js"></script>
</body>
</html>
help me change row via column api the code itself works, I misclicked somewhere and now I can’t find where help please abobaPost is responsible for the change edit post
Hello everyone, I have such a problem that I can’t edit columns in the database through api, everything else works, creating, deleting, etc., but there are no changes in the logs, there are no errors, maybe there is a syntax error somewhere, or I forgot to add something
the code itself works, I misclicked somewhere and now I can’t find where help please abobaPost is responsible for the change edit post