Reputation: 1
$("#MainContent_btnSave").click(function (e) {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
$('#myDiv').text(xmlhttp.responseText);
}
}
xmlhttp.open("POST", "send.php", true);
xmlhttp.send();
e.preventDefault();
});
The javascript code above is javascript function, which is called by clicking on button with id=MainContent_btnSave.
The same request with parameter GET finish successfully.
But with parameter POST xmlhttp.status always equal to 405 and arise error like that: "Command HTTP POST, used to 'send.php', is denied." What can be the problem?
File 'send.php' contain :
<?php
echo "Your email was sent!";
?>
Upvotes: 0
Views: 111
Reputation: 64536
parameter POST xmlhttp.status always equal to 405 and arise error like that: "Command HTTP POST, used to 'send.php', is denied."
A 405 error is Method Not Allowed. This means either: your webserver is blocking the POST request, or your PHP framework is blocking it, or doesn't have a POST route defined for send.php.
Upvotes: 2
Reputation: 526
If you're using jQuery then use it's functions. $.post() for example:
$("#MainContent_btnSave").click(function() {
$.post('send.php', data, function(response) {
$("#myDiv").text(response);
});
});
Upvotes: 2