WHAT I ALREADY LOOKED AT:
Failed to load resource: net::ERR_EMPTY_RESPONSE http://test.com
Failed to load resource under Chrome
Failed to load resource: net::ERR_EMPTY_RESPONSE when console not opened
Failed to load resource: net::ERR_EMPTY_RESPONSE
ERROR:
Failed to load resource: net::ERR_EMPTY_RESPONSE
CODE:
client
var load = 0;
$( document ).ready(function() {
if (load == 0) {
load++;
$.ajax({
type: "POST",
url: "/1/2",
data: someData,
}).done(function(response) {
console.log("RESPONSE :"+response);
if (response.charAt(0) == "F") {
localStorage.setItem("error_msg_local", response);
} else if (response.charAt(0) == "L") {
localStorage.setItem("success_msg_local",response);
} else {
localStorage.setItem("error_msg_local", "Internal error. Please try again.");
}
});
}
});
server
The request is sent with POST and will wait for the user to complete a certain action. If the user does nothing, after 120 seconds, "NO" is logged and "F" should be sent as a response.
router.post("/2", function(req, res, next){
request.post({
url: 'URL:Port',
json: {
JsonData: JsonData,
timeout: "120000"
}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
if (body.status == "success") {
//User completed action within 120 seconds, so do stuff
}
else {
//120 elapsed without user completing action, body.status == "nothing", so execute this:
console.log("NO");
res.send("F");
}
}
else {
console.log("ERROR: "+error);
}
});
});
QUESTION:
I am intentionally waiting 120 seconds to test my code. Nothing is logged on the client, but "NO" is logged on the server, so I know that res.send("F") should have been sent as a response.
Yet, I received "Failed to load resource: net::ERR_EMPTY_RESPONSE" in my browser console as an error message and nothing happens.
Here is everything that logs out in my terminal (server logs):
POST /1/2 - - ms - -
NO
POST /1/2 - - ms - -
NO
Strangely enough, it seems the request is triggered multiple times although I have called it only once ?
I even added a load counter to make sure it gets called only once, but it seems it gets called twice.
What should I do to only have one AJAX request and actually get the proper response from my server ?