I tried to post method in ajax request Method Not Allowed in js and give me Status Code 405 please help me
// js code
const xml = new XMLHttpRequest();
xml.onload = function(){
console.log(this.responseText);
}
xml.open("POST","receive.php",true);
xml.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xml.send("name=kareem&lastvist=Today");
// php code
<?php
foreach ($_POST as $post_var) {
echo strtoupper($post_var)
}
?>
The 405 Method Not Allowed error occurs when the web server is configured in a way that does not allow you to perform a specific action for a particular URL. It’s an HTTP response status code that indicates that the request method is known by the server but is not supported by the target resource.
If you calling XMLHttpRequest().open() this method for an already active request (one for which open() has already been called) is the equivalent of calling abort().