I found the solution. It was all about the PHP file not supporting the post() method.
Two things helped me zero in on the root of the problem. Firstly,
Node.js http-server doesn't run PHP despite serving as a localhost. Secondly,
405 Method Not Allowed response status code indicates that the server knows the request method, but the target resource doesn't support this method. That intrigued me to install a dedicated PHP server. So, I hosted PHP on Windows with IIS as explained
here and
here. Thereafter, I hosted my project folder from within IIS and now, the post() method works perfectly and the two pages communicate as well as required.
However, there was a typo in my code. In the mypost.php file, there will be a
.
after the
$location
variable at the end of the
echo
statement, which I overlooked. That was throwing a 500 (Internal Server Error).
Hope this post helps those in the future facing the same problem.
Regards!