Я получаю HTTP 404 по запросу PUT, как показано ниже:
$(function(){
$("#showMovies").click(function() {
$.ajax({
method:"GET",
url: "http://localhost:3000/movielist",
dataType: "json",
success: function (response) {
$.each(response, function(i, movie) {
const rowText = "<tr>" +
"<td>" + movie.idmovielist + "</td>" +
"<td>" + movie.name + "</td>" +
"<td>" + movie.thumbnail_path + "</td>" +
"<td>" + movie.description + "</td>" +
"<td>" + movie.year_released + "</td>" +
"<td>" + movie.language_released + "</td>" +
"<td>" + "<button button id = \"deleteMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Delete</button>" + "</td>" +
"<td>" + "<button button id = \"editMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Edit</button>" + "</td>";
$("#movies").append(rowText);
});
}
});
});
$("#movieAdded").click(function() {
$.ajax({
method:"POST",
url: "http://localhost:3000/movielist/addMovie",
dataType: "json",
data: {
idmovielist: 10,
name: 'Bubble Gum',
thumnail_path: 'yourieiri.jpg',
description: 'Disturbing',
year_released: '2007',
language_released: 'french'
},
success: function (data) {
$.each(data, function(i, movie) {
const rowText = "<tr>" +
"<td>" + movie.idmovielist + "</td>" +
"<td>" + movie.name + "</td>" +
"<td>" + movie.thumbnail_path + "</td>" +
"<td>" + movie.description + "</td>" +
"<td>" + movie.year_released + "</td>" +
"<td>" + movie.language_released + "</td>" +
"<td>" + "<button button id = \"deleteMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Delete</button>" + "</td>" +
"<td>" + "<button button id = \"editMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Edit</button>" + "</td>";
$("#movies").append(rowText);
});
}
});
});
$.ajax({
method:"DELETE",
url: "http://localhost:3000/movielist/8",
dataType: "json",
success: function (data) {
$.each(data, function(i, movie) {
const rowText = "<tr>" +
"<td>" + movie.idmovielist + "</td>" +
"<td>" + movie.name + "</td>" +
"<td>" + movie.thumbnail_path + "</td>" +
"<td>" + movie.description + "</td>" +
"<td>" + movie.year_released + "</td>" +
"<td>" + movie.language_released + "</td>" +
"<td>" + "<button button id = \"deleteMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Delete</button>" + "</td>" +
"<td>" + "<button button id = \"editMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Edit</button>" + "</td>";
$("#movies").append(rowText);
});
}
});
$.ajax({
method:"PUT",
url: "http://localhost:3000/movielist/6",
dataType: "json",
data: {
idmovielist: 6,
name: 'Lion King',
thumanail_path: 'https://lumiere-a.akamaihd.net/v1/images/',
description: 'cartoon',
year_realeased: '2000',
language_released: 'english'
},
success: function (data) {
$.each(data, function(i, movie) {
const rowText = "<tr>" +
"<td>" + movie.idmovielist + "</td>" +
"<td>" + movie.name + "</td>" +
"<td>" + movie.thumbnail_path + "</td>" +
"<td>" + movie.description + "</td>" +
"<td>" + movie.year_released + "</td>" +
"<td>" + movie.language_released + "</td>" +
"<td>" + "<button button id = \"deleteMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Delete</button>" + "</td>" +
"<td>" + "<button button id = \"editMovie\" type=\"button\" class=\"btn btn-danger\" data-toggle=\"modal\" data-target=\"#exampleModal\">Edit</button>" + "</td>";
$("#movies").append(rowText);
});
}
});
});
Поэтому всякий раз, когда я пытаюсь выполнить свой путзапрос Я всегда получаю эту ошибку с кодом состояния 404 не найден, а также Мои сообщения получения и удаления работают очень хорошо, это только мой запрос о том, что я могу сделать, чтобы исправить это.Также я смог заставить это работать в моем веб-браузере, потому что я забыл добавить функцию
app.put('/movielist/id',(req,res) =>{
let update = req.body;
mysqlConnection.query("UPDATE movielist SET year_released = '2000' WHERE idmovielist = '6'",
[update.year_released, update.idmovielist,req.params.id],
(err, results) => {
if (!err) {
res.send("Movie list is updated");
} else {
console.log(err);
}
});
});
Также мой код запроса почты
app.post('/movielist/addMovie',(req, res) => {
mysqlConnection.query("INSERT INTO movielist (idmovielist, name, thumnail_path, description, year_released,language_released) VALUES ('10', 'Bubble Gum', 'yourieiri.jpg', 'Disturbing', '2007', 'french');",
req.body,
(err,rows) => {
if (!err) {
res.send("Movie is added");
} else {
console.log(err);
}
});
});
app.get('/movielist',(req,res)=> {
mysqlConnection.query("SELECT * FROM movielist", (err, rows,fields)=> {
if (!err) {
res.send(rows);
} else {
console.log(err);
}
});
});
app.delete('/movielist/:id',(req,res) => {
mysqlConnection.query("DELETE FROM movielist WHERE idmovielist = ?",[req.params.id],(err,rows,fields) =>{
if (!err) {
res.send("Movie is deleted");
} else {
console.log(err);
}
});
});
app.post('/movielist/addMovie',(req, res) => {
mysqlConnection.query("INSERT INTO movielist (idmovielist, name, thumnail_path, description, year_released,language_released) VALUES ('10', 'Bubble Gum', 'yourieiri.jpg', 'Disturbing', '2007', 'french');",
req.body,
(err,rows) => {
if (!err) {
res.send("Movie is added");
} else {
console.log(err);
}
});
});
app.put('/movielist/:id',(req,res) =>{
let update = req.body;
mysqlConnection.query("UPDATE movielist SET year_released = '2000' WHERE idmovielist = '6'",
[update.year_released, update.idmovielist,req.params.id],
(err, results) => {
if (!err) {
res.send("Movie list is updated");
} else {
console.log(err);
}
});
});
Почтальон