I have a website served up using Nginx. I've create a very simple web-page with a p tag to display the contents of a file, test.html. I have two buttons, one that does a GET request using $.ajax, and one that does a POST request using $.post.
The GET request works fine, and the contents of the file test.html display in my p tag. When I try to POST to that same file, however, I get an error in the console: "Failed to load resource: the server responded with a status of 405 (Not Allowed)". The POST request is pretty simple, taken right from the example on W3Schools.com - https://www.w3schools.com/JQuery/jquery_ajax_get_post.asp. So I am baffled.
I tried to read and understand what a 405 error could mean. Presumably it means that the POST request is not supported by this URL. But how would I enable it to be supported?
<p id="content-from-ajax"></p>
<button id="get-content-btn">Get Content</button>
<button id="post-something-btn">Post something</button>
<script type="text/javascript">
$("#get-content-btn").click(function() {
$.ajax({type: "GET",
url: "test.html",
success: function(result) {
$("#content-from-ajax").html(result);
alert("GET successful");
}
});
});
$("#post-something-btn").click(function(){
alert("GRRRR");
$.post("test.html",
{
name: "Donald Duck",
city: "Duckburg"
},
function(data, status){
alert("something worked");
});
});
</script>