1

I want to start and stop my EC2 instance on AWS using an HTML button and some JavaScript, if necessary.

I do not want the button to navigate to a new page; it should only perform the start/stop action.

Example HTML:

Click Here To Disable QA Servers : 
<BR><BR> 
<form action="https://*************1.amazonaws.com/stop/stop">
    <input type="submit" value="Click Here!" />
</form>
Arafat Nalkhande
  • 10,003
  • 7
  • 38
  • 61
Ben1
  • 21
  • 1
  • 2
  • both of those 2 solutions not help me.i dont want to open it in new page,just to run it in the background – Ben1 Dec 20 '16 at 19:58

2 Answers2

0

you can use (get / post) request jquery like:

html:

<div>
    ...
    <button id="btn-start">Click to start</button>
    <button id="btn-stop">Click to stop</button>
</div>

jquery:

$('#btn-stop').on('click', function (e) {
    $.get( "https://****1.amazonaws.com/stop/stop", function( data ) {
        // Some logic
    });
});

$('#btn-start').on('click', function (e) {
      $.get( "https://****1.amazonaws.com/start/start", function( data ) {
            // Some logic
      });
 });
Yoan
  • 2,070
  • 11
  • 21
0

Do you mean once you click submit you don't want the page to reload? If so you can use e.preventDefault();. Check out the fiddle. Sorry if I misunderstood the question.

$('form').on('submit', function(e) {
    e.preventDefault();
    console.log('No page reload.');
});

https://jsfiddle.net/zouLcq9v/

justDan
  • 2,167
  • 5
  • 16
  • 28