0

I am encountering a similar situation to XMLHttpRequest status 0 (responseText is empty), but I felt that the difference was strong enough that it deserved it's own question.

So, my HTTPXmlRequest looks like this:

function displayIndicator() {
  alert(loader.responseText);
}

var loader = new XMLHttpRequest();
loader.onload = displayIndicator(); 
loader.open("get", "/products", true);
loader.send();

and /products when loaded in a browser window, or via

curl http://localhost:3000/cart/indicator;

returns a full fledged html document, (Im using it as a test page for the moment, eventually the end point will change but the correct endpoint behaves the same way).

this page is being served by a node server, so it's using a router and /products should resolve correctly wherever the script is being called from which makes me suspect that it's not the usual cross-domain issue.

Any thoughts?

Community
  • 1
  • 1
Crispen Smith
  • 513
  • 4
  • 20
  • Does this answer your question? [Does an HTTP Status code of 0 have any meaning?](https://stackoverflow.com/questions/3825581/does-an-http-status-code-of-0-have-any-meaning) – Michael Freidgeim Dec 24 '21 at 05:22

1 Answers1

1

You're executing the displayIndicator function and assigning its return value (undefined) to loader.onload, you just need to remove the parenthesis:

loader.onload = displayIndicator;
idbehold
  • 16,833
  • 5
  • 47
  • 74