javascript - XMLHttpRequest() returning 0
Get the solution ↓↓↓I have the following javascript which runs when an image is clicked:
function dateBack () {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("hell").innerHTML = httpRequest.responseText;
}
else {
document.getElementById("hell").innerHTML = httpRequest.readyState;
document.getElementById("hell").innerHTML = httpRequest.status;
}
};
httpRequest.open('POST', 'subtractDay.php?depDate=sal', true)
}
and the subtractDay.php which looks like this:
<?php
$depDate = $_REQUEST["depDate"];
echo $depDate;
?>
The code has been edited slightly from my original code for simplicity sake. When I click the image, the element with id "hell" gets the value of 0 which means that the request was not initialized. The file subtractDate.php can be accessed from the same server as the file with the javascript code. Please advise.
Answer
Solution:
it missing.send()
httpRequest.open('POST', 'subtractDay.php?depDate=sal', true)
httpRequest.send(null);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: uncaught error: call to undefined function mysqli_connect()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.