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

114
Visualizações
Send Json object and receive the response at the same time

For a school project, I am to send JSON. The server processes this file and sends me back a response with a JSON. The whole thing should happen with JavaScript. I have now become aware of the XMLHttpRequest, but don't quite understand it.

Do I have to create two objects with GET and POST or is it possible to combine them?

At the moment I have one var httpPost = new XMLHttpRequest(); to send and one to receive var httpGet = new XMLHttpRequest();

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

let's do it with jQuery AJAX api:

let json = {"key":"val"}
$.post("api.php",json, function(response){
    console.log(response)
});

let's do it with Fetch api:

const data = { username: 'example' };
fetch('api.php', { method: 'POST', body: JSON.stringify(data) })
.then(response => {
  console.log('Success:', response);
}) 
about 4 years ago · Santiago Trujillo 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