更新mysql nodejs

时间:2019-04-07 14:52:06

标签: mysql node.js

所以我从本地主机获得了这个阵列

{
"idmovielist": 6,
"name": "Lion King",
"thumnail_path": "https://lumiere-a.akamaihd.net/v1/images/",
"description": "cartoon",
"year_released": "1994",
"language_released": "english"
},

我想根据我的idmovielist更改year_released 这就是我所拥有的

app.put('/movielist/upddate/: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);
    }
});
});
and

当我这样做时,它不会更新注释:我正在写硬编码值 http://localhost:3000/movielist 这是我从那里得到清单的地方

$.ajax({
    method:"PUT",
    url: "http://localhost:3000/movielist/update/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);
      });
    }
});

0 个答案:

没有答案