I did something similar, but not quite what I’m looking for. What I need is to load an url that is being typed down on an input. Eg. I type down “001.xml” and submit it and that is what is going to load.
<!DOCTYPE html>
<html>
<head>
<script>
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "", true);
xhttp.send();
}
</script>
</head>
<body>
<div id="demo">
<h2>Let AJAX change this text</h2>
</div>
<input type="text" id="url"></input>
<button type="button" onclick="loadDoc()">Change Content</button>
</body>
</html>
2
Answers
Try this:
Hope it helps.
What do you want to load? External URL or some query string to your existing page?
Also, you may have to change
<script>
tag where you load jQuery. src should be within script tag.