Appending The Contents Of A Unix Command To A Div Tag
I'm making a UNIX web-based terminal for learning purposes. So far I have made a text box and the output is being displayed. Sort of like this.
Solution 1:
change:
document.getElementById("txtOut").innerHTML=xmlhttp.responseText;
to:
document.getElementById("txtOut").innerHTML += xmlhttp.responseText;
On a sidenote, why are you not using any of the well established javascript frameworks?
With jQuery for example you could reduce your code to maybe 4 lines.
Edit - using jQuery: http://api.jquery.com/jQuery.ajax/
<html><head><linkhref="/css/webterminal.css"type="text/css" /><scripttype="text/javascript"src="http://code.jquery.com/jquery-1.5.2.min.js"></script><scripttype="text/javascript">
$(function () {
$('#cmd').bind('keydown', function (evt) {
if (evt.keyCode === 13) { // enter keyvar cmdStr = $(this).val();
$.ajax({
url: 'exec.php',
dataType: 'text',
data: {
q: cmdStr
},
success: function (response) {
$('#txtOut').append(response);
}
});
}
});
});
</script></head><body><divclass="container"><h2>UNIX Web Based Terminal 1.0</h2><br /><p><b>output</b></p><spanid="User"></span><inputid="cmd"type="text"class="textbox"size="20" /><divclass="output"><p><spanid="txtOut"></span></p></div></div></body></html>
Post a Comment for "Appending The Contents Of A Unix Command To A Div Tag"