DEV Community

Shubham Gujar
Shubham Gujar

Posted on

Problem in sending id of an element as a key using POST request

I've been trying to send the id of an element(button) as a key alone using XMLHttpRequest. I've used application/x-www-form-urlencoded. Since for application/x-www-form-urlencoded, the body of the HTTP message sent to the server is essentially one giant query string -- key/value pairs are separated by the ampersand (&), and keys are separated from values by the equals symbol (=). An example of this would be: KeyOne=ValueOne&KeyTwo=ValueTwo but I want to send the id as a key alone, not as a value. How can I send id as a key, not as a value?

Discussion (1)

linostar profile image

If you want to send anything as a key in an HTTP form, you should put it in the "name" attribute not in the "id" attribute of the HTML element (of course it is ok to put it in both).