删除方法未执行

时间:2019-06-26 08:20:46

标签: jquery

我的删除方法有效。它显示200 OK状态,但是当我单击“确定”以确认删除时,没有任何改变,即使刷新页面也没有改变。下面是我的前端和用户界面的屏幕截图:

enter image description here

我之前也进行过类似的申请,但此方法对我有用,但由于某种原因它不起作用。让我知道我可以解决的问题。这是我的删除功能。

$("body").on('click', '.deleteStudent', function(a) {
  a.preventDefault();
  var student_id = $(this).data('studentid');
  console.log(a);

  $.ajax({
    url: "http://localhost:3200/students/deleteStudent/" + student_id,
    method: 'DELETE',
    dataType: 'json',
  }).always(function(data) {
    console.log(data);
    showStudents();
    confirm("You want to delete this");
  });
});

  $("#movieAdded").click(function(a) {
      a.preventDefault();
    let mydata = {
      idmovielist: $($("#newForm")[0].intNum).val(),
      name: $($("#newForm")[0].name).val(),
      thumnail_path: $($("#newForm")[0].thumnail_path).val(),
      description: $($("#newForm")[0].description).val(),
      year_released: $($("#newForm")[0].year_released).val(),
      language_released: $($("#newForm")[0].language_released).val(),
    }

    $("#newForm").trigger("reset");
    $("#newForm").toggle();
    $.ajax({
      method: "POST",
      url: "http://localhost:3000/movielist/addMovie",
      dataType: "json",
      data: mydata,
  }).always(function(data){
        console.log('always',data);
        renderMovieList();
    });
  });
  $('#updateMovie').click(function(a) {
    a.preventDefault();
    let updatedata = {
      idmovielist: $($("#updateForm")[0].movie_id).val(),
      name: $($("#updateForm")[0].edit_name).val(),
      thumnail_path: $($("#updateForm")[0].edit_thumnail_path).val(),
      description: $($("#updateForm")[0].edit_description).val(),
      year_released: $($("#updateForm")[0].edit_year_released).val(),
      language_released: $($("#updateForm")[0].edit_language_released).val(),
    }

    $("#updateForm").trigger("reset");
    $("#updateForm").toggle();

    $.ajax({
      url: "http://localhost:3000/movielist/updateMovie/18",
      method: 'PUT',
      dataType: 'json',
      data: updatedata,
    }).always(function(data){
          console.log(data);
          renderMovieList();
  });

  });
function renderMovieList() {
  $.ajax({
    method: "GET",
    url: "http://localhost:3000/movielist",
    dataType: "json",
    success: function(response) {
      $('#movies').empty();
      $.each(response, function(i, movie) {
        const rowText = "<tr>" +
          "<td>" + movie.idmovielist + "</td>" +
          "<td>" + movie.name + "</td>" +
          "<td>" + movie.thumnail_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 deleteMovie\"  data-movieid=" + movie.idmovielist + ">Delete</button>" + "</td>" +
          "<td><button type='button' class='btn btn-danger edit-movie' data-toggle='modal' data-target1='#exampleModal2' data-movieid=" + movie.idmovielist + ">Edit</button></td>";
        $("#movies").append(rowText);
      });
    }
  });
}

0 个答案:

没有答案