weixin_33690367 2016-04-15 11:20 采纳率: 0%
浏览 221

XMLHttpRequest.responseText

Usually if we want to get some data with AJAX we do something like that:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 && xhr.status == 200){
        elem.innerHTML = xhr.responseText;          
    }
}

And the question is - can we get the result not as elem.innerHTML but as is?

I mean:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 && xhr.status == 200){
        xhr.responseText;           
    }
}

The problem is that result of my query is HTML-table made by PHP and I don't want to wrap it with some other elements.

  • 写回答

1条回答 默认 最新

  • 乱世@小熊 2016-04-15 11:26
    关注

    You can use

    elem.innerText = xhr.responseText;
    

    Watch out though: the innerText property is read-only on the html, table, tBody, tFoot, tHead, and tr objects. When the innerText property is set, the given string completely replaces the existing content of the object.

    评论

报告相同问题?