jquery - 我需要一个 AJAX 脚本来加载提交时在输入中输入的 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>
解决方案
你要加载什么?您现有页面的外部 URL 或一些查询字符串?此外,您可能必须更改<script>
加载 jQuery 的标签。src 应该在脚本标签内。
推荐阅读
- mysql - 是否可以在子查询中返回多于一行
- android - Android Studio - 功能可以“知道”按下哪个按钮激活它吗?
- uwp - 为商店应用程序形成广告系列网址时,是否有类似“companyID”的内容?
- python - 正则表达式与 python
- flutter - 如何在颤振中添加图像轮播
- linux - Boost: 未定义引用 '__xstat64', '__lxstat64', '__errno_location' 错误
- android - 当用户允许权限时,我在 onRequestPermissionsResult 中授予权限的函数没有调用
- python - 如何按列中的值分组,查找空值,然后替换
- javascript - 圆环图:显示里面的百分比
- testing - DerivedData 中缺少 TestSummeries.plist 文件