I want to mimic a CLI in a web page, where a user types in a command on the page, and it is sent to the server for execution, and the response is displayed in the page - much like a CLI behavior.
My jQuery fu is not what it should be and I am thinking that this must be a 'pattern' that must occur quite often so maybe someone can point to a resource somewhere that has similar code, or maybe someone can get me started with a snippet posted in here.
Here is my first stab at it. Corrections, improvements welcome.
<html>
<head>
<title>Simple CLI</title>
<script src="jquery.js">
</head>
<body>
<div>
<div id="console">
</div>
<!-- Is having an input tag without an enclosing form tag valid (X)HTML? -->
<input id="cmd_input" type="text" name="cli_cmd" />
<div
<script type="text/javascript">
/* [CDATA[ */
$(document).ready(function(){
$.post('url': "example.php", {'cmd': $('#cmd_input').val()},
function(data){ $('#cmd_input').append(data.resp); },
'type': 'json');
});
/* ]]> */
</script>
</body>
</html>