Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!