Created
December 19, 2017 01:07
-
-
Save brianonn/1561949f6dbd090dd032bdf18a12218d to your computer and use it in GitHub Desktop.
test loading XHR content into an iframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id='body'> | |
<h1>this is a header</h1> | |
<iframe id='iframe' /> | |
</div> | |
<p id='responseText'> | |
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var website = 'https://notpibsb0j.execute-api.us-east-2.amazonaws.com/Prod/'; | |
var xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
// Typical action to be performed when the document is ready: | |
console.log(xhttp.responseText); | |
var iframe= document.getElementById('iframe').contentWindow.document | |
iframe.open(); | |
iframe.write(xhttp.responseText); | |
iframe.write('<p><strong>Test from Brian<strong></p>') | |
iframe.close(); | |
$('#iframe').contents().find('body').append('<p>Test</p>'); | |
} | |
}; | |
setTimeout( () => { | |
xhttp.open("GET", website, true); | |
xhttp.send(); | |
}, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment