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

106
Visualizações
Restfull service only responds to first request

I'm dealing with a small web app and having some trouble with XMLHttpRequest. I'm trying to send one POST request and then a GET all towards the same REST endpoint.

I think that the problem is somewhere in the XMLHttp object itself. Maybe the connection from the first is not properly closed.

First POST request to REST service update news

function send_response(id_str, sentiment) {
    if (glob_id != null) {
        id_str = initial_id
    }
    id = parseInt(id_str)
    if (typeof (id) === 'number' && id > 0 && id < 200000) {
        let req = new XMLHttpRequest();
        req.open('POST', 'http://127.0.0.1:5000/update_news', true);
        req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        req.send(JSON.stringify({"id": id_str, "sentiment": sentiment}));
        req.onreadystatechange = function (aEvt) {
            if (req.readyState == 4) {
                if (req.status == 200) {
                    console.log((req.response));
                    glob_id = req.response['id']
                    update_content();
                } else {
                    console.error("Error loading page\n");
                }
            }
        };
    } else {
        console.warn("what are you trying!")
    }
}

As you can see, the second HTTP request is triggered once the 200 response code is received. However, even though having stepped into update_content() (function in which the GET request is sent), no request is actually sent.

Second GET request to the same REST service

function update_content(){
    let req = new XMLHttpRequest();
        req.open('GET', 'http://127.0.0.1:5000/update_news', true);
        req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        req.onreadystatechange = function (aEvt) {
            if (req.readyState == 4) {
                if (req.status == 200) {
                    console.log((req.response));
                    document.getElementById("news_content") = req.response['content']
                    glob_id = req.response['id']
                } else {
                    console.error("Error loading page\n");
                }
            }
        };
}

Any thoughts about this?

about 4 years ago · Juan Pablo Isaza
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