1 year ago
#379791
deadlock
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?
javascript
rest
xmlhttprequest
0 Answers
Your Answer