Making PUT request to work

adil ali
adil ali used Ask the Experts™
on
Capture35.PNG
I have an issue with my put request it says status 404 not found
$(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);
      });
    }
});
});

Open in new window

Here is my jscode GET DELETE and POST work but put has some issue
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
You'll need to check your server-side code - probably somewhere in your controller - to make sure you have a handler / route for the PUT verb. How you do that will depend on your framework / codebase.

You may also need to configure your server if you're using IIS.

Author

Commented:
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);
    }
});
});

This is my server side for node js
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
OK. I'm not familiar with Node so you may want to update the question Topics to include NodeJS.

To test your setup, I would try making a PUT request directly to your server without using jQuery or AJAX. This will help you know whether the problem is with your script, or with your server setup. For example, if you can successfully make a direct PUT request, then you know your server is set up correctly and focus on your script. If you can't make a PUT request directly, then you know it's your server.

Making requests directly to your API is a lot easier if you use a tool such as Postman.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial