ksmatthews Posted November 14, 2007 Share Posted November 14, 2007 HI Gurus, I am trying to run unix system commands by linking them to button clicks .. For example I can run a system command like this: exec($command); But how can I link this to a button click WITHOUT having to submit a form to the web server ? THe following code (unsurprisingly) will not work <INPUT class = "button" TYPE="submit" id="stop_button" NAME="stop_button" VALUE="STOP" onClick = "exec($command)" /> because onclick event should be tied to a javascript function. Any suggestions ? Steven M Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 14, 2007 Share Posted November 14, 2007 You'll need to use AJAX if you want to avoid an entire page reload. If you google, you'll find plently of examples. Wether or not you'll find something showing exactly what you want to do, i dont know, but the process will be the same - the javascript will make a request to a php page which will run the system command for you. Quote Link to comment Share on other sites More sharing options...
atlanta Posted November 14, 2007 Share Posted November 14, 2007 put this in your html file <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.[color=red]formname[/color].[color=red]status[/color].value = ajaxRequest.responseText; } } ajaxRequest.open("GET", "file.php", true); ajaxRequest.send(null); } //--> </script> Status:<input type="text" name="status" value="" disabled> <INPUT class="button" TYPE="submit" id="stop_button" NAME="stop_button" VALUE="STOP" onClick = "ajaxFunction();" /> Then create a php file which will run the command like this <?php $command = "command"; if(exec($command)) { echo "Stopped"; } else { echo "Error"; } ?> Try that out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.