I have added a submit button to the index.html
page that resides on my server side
<form method="get" action="/start">
<h5>Start Ad-Placer!</h5>
<input type="submit" value="Start">
</form>
I need the button to simply send a http
request to http://127.0.0.1:8484/get/start
to start some process. Then once the process is done after a few seconds, I need to simply display an alert message with the response message, acknowledging it is done.
How can I do that with minimum efforts (without using JQuery or other libraries).
Client/server architecture The server answers the request using the same protocol. An HTML form on a web page is nothing more than a convenient user-friendly way to configure an HTTP request to send data to a server. This enables the user to provide information to be delivered in the HTTP request.
The <input type="submit"> defines a submit button which submits all form values to a form-handler. The form-handler is typically a server page with a script for processing the input data. The form-handler is specified in the form's action attribute.
Submit buttons don't submit if they are not in a form. Not sure why you think form's can't be in a table? (As you already wrote in the title:) The button has no form associated to .... - So asking the question contains the answer: Add the form which is yet missing.
Using submit buttons. <input type="submit"> buttons are used to submit forms. If you want to create a custom button and then customize the behavior using JavaScript, you need to use <input type="button"> , or better still, a <button> element.
If you try something like this you can send a HTTP request and then alert a response. Just change https://google.com to your 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With