Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda