views:

579

answers:

4

Is it possible to detect the HTTP request method (e.g. GET or POST) of a page from JavaScript? If so, how?

+3  A: 

In a word - No

Kevin
+1  A: 

You cant do this for a normal post/get however you can get to this info if you use an xmlhttp call and use the getResponseHeader

redsquare
+1  A: 

If you need this functionality, have the server detect what method was used and then modify something in the DOM that you can then read out later.

Daniel Papasian
+2  A: 

I don't believe so. If you need this information, I suggest including a <meta> element generated on the server that you can check with JavaScript.

For example, with PHP:

<meta id="request-method" name="request-method" content="<?php echo($_SERVER['REQUEST_METHOD']); ?>">
<script type="text/javascript">
    alert(document.getElementById("request-method").content);
</script>
Jim