문제

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?

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top