“getElementById not a function” when trying to parse an AJAX response?

后端 未结 3 643
死守一世寂寞
死守一世寂寞 2020-11-29 10:36

I\'m running GM_xmlhttpRequest (in a Greasemonkey script) and storing the responseText into a newly created HTML element:

var respo         


        
3条回答
  •  独厮守ぢ
    2020-11-29 11:40

    There is no need to store the response in an element neither use DOMParser()

    Just set the responseType to 'document' and the response will be parsed automatically and stored in the responseXML

    Example:

    var ajax = new XMLHttpRequest();
    ajax.open('get','http://www.taringa.net');
    ajax.responseType = 'document';
    ajax.onload = function(){
        console.log(ajax.responseXML); //And this is a document which may execute getElementById
    };
    ajax.send();
    

提交回复
热议问题