我有两个php页面。第一页将加载到客户端浏览器和显示按钮。如果点击它将使用Ajax调用来执行我的第二个PHP页面。第二个php页面使用ssh2_exec连接到服务器,执行一些shell脚本并在不刷新的情况下在同一个加载的页面上显示输出。我可以用我现有的页面来实现这一点。但它在第二页完成执行后立即显示完整的输出。我希望作为第二个php页面开始执行,输出应该在客户端浏览器上逐行显示。如何使用ajax在运行时显示shell脚本的输出
下面是我的2页:
PHP第1页:
function disable()
{
document.getElementById("save").disabled = true;
}
function enable_button()
{
document.getElementById("save").disabled = false;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('output').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', 'arg0_orgcmd_exec.php?id=118' , true);
xmlhttp.send();
}
function disable_button()
{
document.getElementById("execute").disabled = true;
}