How to read the post request parameters using JavaScript

I am trying to read the post request parameters from my HTML. I can read the get request parameters using the following code in JavaScript.

$wnd.location.search

But it does not work for post request. Can anyone tell me how to read the post request parameter values in my HTML using JavaScript?


POST data is data that is handled server side. And Javascript is on client side. So there is no way you can read a post data using JavaScript.


A little piece of PHP to get the server to populate a JavaScript variable is quick and easy:

var my_javascript_variable = <?php echo json_encode($_POST['my_post'] ?? null) ?>;

Then just access the JavaScript variable in the normal way.

Note there is no guarantee any given data or kind of data will be posted unless you check - all input fields are suggestions, not guarantees.