Jquery 我需要一个AJAX脚本来加载提交时在输入中键入的URL

Jquery 我需要一个AJAX脚本来加载提交时在输入中键入的URL,jquery,html,ajax,Jquery,Html,Ajax,我做了类似的事情,但不完全是我想要的。我需要的是加载一个url,该url正在输入中键入。我键入“001.xml”并提交它,这就是要加载的内容 <!DOCTYPE html> <html> <head> <script> src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="

我做了类似的事情,但不完全是我想要的。我需要的是加载一个url,该url正在输入中键入。我键入“001.xml”并提交它,这就是要加载的内容

<!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>

src=”https://code.jquery.com/jquery-3.4.1.js"
integrity=“sha256-WPOOHJOQQYKL9FCCASB9O0KWACQJPFTUBLTYOVV=”
crossorigin=“匿名”>
函数loadDoc(){
var xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“demo”).innerHTML=this.responseText;
}
};
xhttp.open(“GET”,“”,true);
xhttp.send();
}
让AJAX更改此文本
更改内容
试试这个:

function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  var url = document.getElementById("url").value;
  xhttp.open("GET", url, true);
  xhttp.send();

}
希望有帮助。

试试这个:

function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  var url = document.getElementById("url").value;
  xhttp.open("GET", url, true);
  xhttp.send();

}

希望有帮助。

您想加载什么?现有页面的外部URL或某些查询字符串?
此外,您可能必须更改加载jQuery的
标记。src应该在脚本标记中。

要加载什么?现有页面的外部URL或某些查询字符串?
此外,您可能必须更改加载jQuery的
标记。src应该在script标签中。

到目前为止您做了什么?将你的代码添加到问题中我更新了它,谢谢你的关注@Majedbadawi到目前为止你做了什么?将您的代码添加到问题中我更新了它,感谢您对@MajedBadawiThanks的兴趣,非常快速的回答,并且准确。谢谢,非常快速的回答,并且准确。