Home » Jquery » javascript – POST 405 Ajax (Method Not Allowed)

javascript – POST 405 Ajax (Method Not Allowed)

Posted by: admin February 22, 2020 Leave a comment

Questions:

When I use GET, it works. I used this code before but it doesn’t work here. What is the way to solve this? Is the problem due to my jQuery Version?

xammp LocalHost

[index.html]
$(document).ready(function () {
  $("button").click(function () {
    var nick = $('input[name="nick"]').val();
    var pin = $('input[name="pin"]').val();
    if (nick == "" && pin == "") {
      document.getElementById("div").innerHTML = "Lütfen boş alan bırakmayın.";
    } else {
      alert(nick); 
      alert(pin);

      $.ajax({
        type: 'POST',
        url: '/kontrol.php',
        data: { nick },
        success: function(cevap) {
          $("#sonuc").html(cevap);
          document.getElementById("div").innerHTML = "s boş alan bırakmayın.";
        }
      })
    }
  });
});
[Kontrol.php]
<?php 
  $json = $_POST['pin'];
  $json2 = $_POST['nick'];

  echo $json;
  echo $json2;
?>
How to&Answer: