【发布时间】:2022-12-01 14:12:42
【问题描述】:
I am new in web, I am serving an html when a button is clicked on the client side through a request, the body response of that request is the html. How can I retrieve the html or body response from the client side?
I am trying with this code but everything is empty:
var xhr = new XMLHttpRequest();
xhr.open(signedRequest.method, signedRequest.url, true);
console.log('xhr.response: ', xhr.response);
console.log('xhr.responseText: ', xhr.responseText);
console.log('xhr.responseXML: ', xhr.responseXML);
document.write('<p>xhr: ' + xhr + '</p>');
xhr.send();
Any idea on how to obtain the body response in the client-side?
【问题讨论】:
-
So the responseText does not have the content? Are you running into CORS problem?
-
Note: synchronous requests are a bad idea. You should ideally use fetch.
-
Thanks @epascarello for your cmets, I'm not running into CORS problem, the html is served but I can't obtain the body response. I'll switch to fetch, thanks.
-
So the responseText has no content?
-
@frankh07 Did you have a look at the answer I provided?
标签: javascript html http xmlhttprequest response