JQuery - a POST request is a GET request .. how did it happen?

I have never had such a problem and am very puzzled:

function delete_post(id) {
  var answer = confirm("Are you sure you want to delete your post? (this action cannot be undone)")

  if (answer) {
    $.ajax({ 
      method:"post",
      url: "ajax/delete.php",
      data:"id="+id,
      beforeSend: function(){ $('#delete_post').show('slow'); },
      success: function(html) { $("#delete_post").html(html); }
    });
  }
  else {}
  return false;
}

I had a problem on the server side, and after analyzing the output with firebug, I noticed that the request turned out to be GET instead of the message! What am I missing here?

+3
source share
1 answer

Oh easy. A property is the type of not method:

$.ajax({ 
  type:"POST",
  url: "ajax/delete.php",
  data:"id="+id,
  beforeSend: function() {
    $('#delete_post').show('slow');
  },
  success: function(html) {
    $("#delete_post").html(html);
  }
});

Note: from the documentation, the method (type) is in uppercase ('GET', 'POST "). I really don't know if this has a value or not.

+3
source

Source: https://habr.com/ru/post/1706167/


All Articles