I need to get statuses(http codes) of static files on page.
(我需要在页面上获取静态文件的状态(http代码)。)
For example html code contains
(例如html代码包含)
<link rel="stylesheet" type="text/css" href="theme.css">
<link rel="stylesheet" type="text/css" href="https://example.com/theme.css">
<script src="script.js"></script>
<script src="https://example.com/script.js"></script>
<img src="image.png">
<img src="https://example.com/image.png">
On output need to get json like this Only 404 needed.
(在输出上需要像这样获取json仅需要404。)
{
"css": [
{
"https://example.com/theme.css": "404",
"https://example2.com/theme.css": "404"
}
],
"js": [
{
"https://example1.com/script.js": "404",
"https://example.com/script.js": "404"
}
],
"images": [
{
"https://example.com/image.png": "404",
"https://example.com/image.png": "404"
}
]
}
It must be done with only Javascript.
(必须仅使用Javascript完成。)
I am going to use this
(我要用这个)
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
It is necessary that upon receiving the status, this should not be done by executing a separate GET request to the file.
(有必要在收到状态后,不要通过对文件执行单独的GET请求来完成此操作。)
But I can't find the way how to do this without executing a separate GET request.
(但是我找不到执行单独的GET请求的方法。)
Who can find the solution?
(谁可以找到解决方案?)
ask by XueQing translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…