检查来自XMLHttpRequest的响应

时间:2019-02-17 10:07:07

标签: javascript xmlhttprequest

我需要检查我的xhr请求是否以#document或错误的形式返回响应。

enter image description here

可能是其他错误,如上图所示(#403,net:ERR ...) 好吧。

我将附加我的代码,并告诉你我需要帮助的地方。 我的getHTML函数。

let getHTML = function ( url, callback ) {

// Feature detection
if ( !window.XMLHttpRequest ) return;

// Create new request
let xhr = new XMLHttpRequest();

// Setup callback
xhr.onload = function() {
  if ( callback && typeof( callback ) === 'function' ) {
    callback( this.responseXML );
  }
}

// Get the HTML
xhr.open( 'GET', url );
xhr.responseType = 'document';
xhr.send();

};

const domains = [];

以及需要帮助的地方:

getHTML('https://www.brandnames.net/shop/?count=5', function (response) {
    const nodeListDomains = Array.from(response.querySelectorAll( '.product-loop-title' ));
    for(let i=0; i<nodeListDomains.length; i++){
        getHTML(`http://${nodeListDomains[i].text}`, function (response){
           if(response){
               console.log(response)
           }
            **WHAT TO WRITE HERE TO GET ONLY WORKING RESPONSE, BUT NOT ERRORS? AND THE SAME FOR ERRORS, BUT NOT WORKING RESPONSE**
        })
    }
})

主要任务:我的客户有一个出售域名的网站(brandnames.net/shop/),我们将所有域名都重定向到了我们的登录页面,但是有些域名并不指向着陆器,因此我需要检查什么。希望你能理解我想说的。

0 个答案:

没有答案