我已经添加了一个提交按钮index.html
驻留在我的服务器端的页面
<form method="get" action="/start">
<h5>Start Ad-Placer!</h5>
<input type="submit" value="Start">
</form>
我需要按钮来简单地发送http
请求http://127.0.0.1:8484/get/start
开始一些过程。然后,一旦该过程在几秒钟后完成,我只需显示一条带有响应消息的警报消息,确认它已完成。
我怎样才能以最小的努力做到这一点(不使用 JQuery 或其他库)。
如果您尝试类似的操作,您可以发送 HTTP 请求,然后发出响应警报。只是改变https://google.com https://google.com到您的网址。
<h5>Start Ad-Placer!</h5>
<input type="submit" value="Start" onclick="submit()">
<script type="text/javascript">
function submit() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
alert(xhr.response);
}
}
xhr.open('get', 'https://google.com', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr.send();
}
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)