1, currently learning AJAX, encountered a problem in following the tutorials, using getAllResponseHeaders can not get the ResponseHeaders data of the page. A novice, the current self-study front-end, what questions are inappropriate, I hope you do not mind, thank you.
2. If there is a problem, console.log (the result returned by this.getAllResponseHeaders ()) is shown in the figure
:
here is my code
<script>
let xhr = new XMLHttpRequest();
console.log(xhr.readyState);
// ==>0
//
xhr.open("get", "http://localhost/time.php");
console.log(xhr.readyState);
// ==> 1
// open
xhr.send();
xhr.addEventListener("readystatechange", function () {
// if (this.readyState !== 4) {
// return false;
// }
// console.log(this.responseText);
// console.log(this.readyState);
switch (this.readyState) {
case 2:
console.log(this.getAllResponseHeaders());
console.log(this.responseText);
// ==> 2
//
break;
case 3:
console.log(this.readyState);
break;
case 4:
console.log(this.readyState);
break;
}
});
</script>
<?php
//
header("Access-Control-Allow-Origin:*");
//
header("Access-Control-Allow-Methods:PUT,GET,POST,HEAD,DELETE");
//
header("Access-Control-Allow-Headers:x-requested-with,content-type");
header("Access-Control-Expose-Headers:X-Pagination-Current-Page,Content-Type");
echo time();
3. What can I do to achieve the effect in the tutorial? So far, we have tried to search the website, but there is no way to solve the problem. Because I have just studied, I can"t understand some of the information found on the Internet. I hope I can get your help. Thank you.
4, Here are the relevant materials I have seen:
https://codeshelper.com/q/10.
https://codeshelper.com/q/10.
https://blog.csdn.net/fdipzon.
http://www.ruanyifeng.com/blo.