Cistko się zgadza.
JS:
<script type="text/javascript"> function post_cmd(cmd){
new Ajax.Request('ajax.php',
{method:'post',
parameters:{ command: cmd },
onSuccess: function(obj){
if(cmd=='/clear'){
document.getElementById('main-window').innerHTML = '';
}
document.getElementById('main-window').innerHTML=document.getElementById('main-window').innerHTML+obj.responseText;
var objDiv = document.getElementById("main-window");
objDiv.scrollTop = objDiv.scrollHeight;
},
onFailure: function(){
alert("Błąd serwera.");
}
});
document.getElementById('cmd').value='';
document.getElementById('cmd').focus();
}
function init(){
new Ajax.Request('ajax.php',{
method:'get',
parameters:{
akcja: 'init'
},
onSuccess: function(obj){
document.getElementById('main-window').innerHTML=obj.responseText;
var objDiv = document.getElementById("main-window");
objDiv.scrollTop = objDiv.scrollHeight;
},
onFailure: function(){
alert("Błąd serwera.");
}
});
document.getElementById('cmd').value = '';
document.getElementById('cmd').focus();
}
function check_msg(){
new Ajax.Request('ajax.php',{
method:'get',
parameters:{
akcja: 'check'
},
onSuccess: function(obj){
document.getElementById('main-window').innerHTML=document.getElementById('main-window').innerHTML+obj.responseText;
var objDiv = document.getElementById("main-window");
objDiv.scrollTop = objDiv.scrollHeight;
},
onFailure: function(){
alert("Błąd serwera.");
}
})
}
function checkenter(event){
event = (event)?event:((window.event)?event:null);
if(event.keyCode==13){
post_cmd(document.getElementById('cmd').value);
}
}
ajax.php:
<?php
header("Content-type:text/html; charset=utf-8");
require("konsola.class.php");
$konsolaobj = new Konsola();
if(!empty($_GET['akcja']) and
$_GET['akcja']=='init'){ $konsolaobj->put('Maxiks Console', 'important');
$konsolaobj->put('Version 0.1Beta', 'info');
$konsolaobj->put('Wpisz komendę...', 'info');
$konsolaobj->ajax_check();
} elseif(!empty($_POST['command'])){ $konsolaobj->parse_cmd(strip_tags($_POST['command'])); } elseif(!empty($_GET['akcja']) and
$_GET['akcja']=='add'){ $konsolaobj->put('Wpis dodany bez sprawdzenia', 'important');
$konsolaobj->put('Kolejny...', 'info');
$konsolaobj->put('I ostatni...', 'error');
}
?>
W przegladarce wywołuję ajax.php?akcja=add.
Udało mi się rozwiązać problem. Konstruktor czyścił po prostu wpisy. Wystarczyło dodać instrukcję warunkową. Dzięki za pomoc.