我向驻留在服务器端的index.html页面添加了一个提交按钮
<form method="get" action="/start">
<h5>Start Ad-Placer!</h5>
<input type="submit" value="Start">
</form>我需要这个按钮来简单地向http://127.0.0.1:8484/get/start发送一个http请求来启动一些进程。然后,在几秒钟后完成该过程后,我只需显示一条带有响应消息的警报消息,以确认该过程已完成。
我如何才能以最小的努力做到这一点(不使用JQuery或其他库)。
发布于 2017-08-16 00:57:16
如果你尝试这样做,你可以发送一个HTTP请求,然后警告一个响应。只需将https://google.com更改为您的URL。
<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>https://stackoverflow.com/questions/45697176
复制相似问题