Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
How can I send the id of an element as a name using POST request?

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 -- name/value pairs are separated by the ampersand (&), and names are separated from values by the equals symbol (=). An example of this would be: MyVariableOne=ValueOne&MyVariableTwo=ValueTwo but I want to send the id as a variable, not as a value. How can I send id as a variable? Following is my program: Thanks in Advance.

<HTML>
<head>
<script>
function fun1(element) {
    var xhttp = new XMLHttpRequest();
    xhttp.open("POST", "/prc", true);
    xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
    xhttp.send(element.id);
    //alert("ID":element.id);
  }
</script>
</head>
<body>
<button type="button" onclick="fun1(this)" id="img1">IMAGE</button>
</body>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You will have to create a FormData object, add your data to that object and send that object. Refer to this documentation.

var formData = new FormData();
formData.append("MyVariableOne", "ValueOne");
formData.append("id", 123456);

var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/prc", true);
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
xhttp.send(formData);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda