XHR responseText is empty string

安稳与你 提交于 2019-11-28 13:58:33

The call to send is asynchronous (you've set the 'async' parameter to true), which means that your alert is happening immediately, before the request finishes. You should add an event-listener to xhr.onreadystatechange and use the response within that.

Changing the 'true' to 'false' would make this simple example work, but is not a good idea in the general case.

The MDN page on Ajax explains how XMLHttpRequest should be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!