XHR responseText is empty string

前端 未结 1 739
天命终不由人
天命终不由人 2020-12-11 23:37

Html Page:




    
    xhr

&l         


        
相关标签:
1条回答
  • 2020-12-11 23:56

    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.

    0 讨论(0)
提交回复
热议问题