on-internet
← Community

how can I parse an HTML response text of an XMLHttpRequest using JS?

Stack Overflow ·

here is my code : const http = new XMLHttpRequest(); const url = 'http://page/'; http.open('get', url, false); http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); http.onreadystatechange = function () { if(http.readyState === 4) { if(http.status === 200 || http.status == 0) { let str = (http.responseText); results = document.getElementById('test').value; alert(results) } } } http.send(); How can I sort the str into html so I can get the value using document.getElementById? I have tried var doc = document.implementation.createHTMLDocument("example"); doc.documentElement.

Comments

Sign in or sign up to comment and upvote.

No comments yet.