I am attempting to make a dead simple webpage that does things when I click a button.
I am trying to use Javascript so I don’t have to reload the main page or anything.
So I want a button that says “Shutdown”, and I simply want to run shutDown.php that will shut down the server when I click on this.
I’ve been searching for an hour now and can’t find a simple example. Could someone please post a very simple, example, or a link to one?
Many thanks 🙂
EDIT:
Okay so here’s my pitiful attempt.. it doesn’t work.. any tips?
<html>
<head>
<title>Control Page</title>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript">
/*************************************
JQUERY EXAMPLE
*************************************/
$('#mysubmit').click(){
var jqueryXHR = $.ajax({
'type': 'POST',
'url': 'http://localhost/killIE.php',
'dataType': 'json'
});
}
}
</script>
<input type="submit" name="mysubmit" value="Click!" />
</body>
</html>
Yep – technology called called AJAX.
You can either write it in raw javascript or use ready made libraries.
The most popular JS library nowadays (subjectively) is jQuery, I’ll use it in my example.
NOTE: this will trigger your shutDown.php PHP script on the server without reloading the page. But – you won’t be able to parse web requests obviously after you shutdown your server :)…
P.S. I assume that you know that you have to load jQuery library first in your html file header, something like this:
And then put that jquery code inside of script tags:
UPDATED BY REQUEST – complete script version