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

122
Visualizações
Why AJAX POST request failed?

I have simple a html page with form. When I do POST request then receive failed, but it not response from server. What I do wrong?

function createRequest(url, body) {
    var response;
    console.log(JSON.stringify(body)); // (1)
    $.ajax({
        url: "creation/" + url,
        type: "POST",
        async: false,
        contentType: 'application/json',
        data: JSON.stringify(body),
        success: function (data) {
            if (data.status == true) {
                response = data.response;
            } else {
                BootstrapDialog.show({
                    title: 'Error',
                    message: data.errorMessage
                });
            }
        }
    });
    return response;
}

Body (1)

{"name":"Test UI","bid":"2","budget":"20"}

When I do this request via POSTMAN all work fine.

jQuery

Error appaear in Chroome Version 57.0.2987.98 (64-bit), but in Edge all works fine enter image description here

enter image description here

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

0

Since there isn't much information you have shared; here are some tips you could use to debug your problem based of assumptions where I think the problem is at.

  1. debug your code by using a console.log(data) as the first thing in your code to make sure if you're accessing the right fields.
  2. data.status is usually a status code 1xx,2xx, 3xx, 4xx and 200 means the success of a request. I check if a response is successful like this data.status == 200, but you used data.status == true you should log the data to make sure you're using that correctly otherwise you'll always get a logged error.
  3. JSON.stringify(body) will convert the body into a string and the data field of an ajax call takes an object with parameters to pass in its request. Is JSON.stringify(body) really what you meant to do or is it just body?

Well if you decide to add more information I'll be sure to update the answer with additional suspicions.

over 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