Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client-side detection of HTTP request method

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

like image 896
Soldarnal Avatar asked Sep 23 '08 14:09

Soldarnal


People also ask

Which HTTP methods are used to show the client?

The primary or most commonly-used HTTP methods are POST, GET, PUT, PATCH, and DELETE.

What are the 4 types of HTTP request methods?

The most commonly used HTTP request methods are GET, POST, PUT, PATCH, and DELETE.

What are the 2 main HTTP request methods?

The two most common HTTP methods are: GET and POST.

What is HTTP request client?

An HTTP request is made by a client, to a named host, which is located on a server. The aim of the request is to access a resource on the server. To make the request, the client uses components of a URL (Uniform Resource Locator), which includes the information needed to access the resource.


2 Answers

In a word - No

like image 182
Kevin Avatar answered Oct 07 '22 18:10

Kevin


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 htmlentities($_SERVER['REQUEST_METHOD']); ?>"> <script type="text/javascript">     alert(document.getElementById("request-method").content); </script> 
like image 36
Jim Avatar answered Oct 07 '22 18:10

Jim