asta e codul js:
Cod: Selectaţi tot
function get_XmlHttp() {
var xmlHttp = null;
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
function ajaxrequest(formular, tagID) {
var cerere_http = get_XmlHttp();
var numele = formular.nume.value;
var mesajul = formular.mesaj.value;
var datele = 'nume='+numele+'&mesaj='+mesajul;
cerere_http.open("POST", 'add.php', true);
cerere_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
cerere_http.send(datele);
cerere_http.onreadystatechange = function() {
if (cerere_http.readyState == 4) {
document.getElementById(tagID).innerHTML = cerere_http.responseText;
}
}
}
Cod: Selectaţi tot
<?php
include("config.php");
if (isset($_POST['nume']) && isset($_POST['mesaj'])) {
$nume = $_POST['nume'];
$mesaj = $_POST['mesaj'];
if (strlen($nume)>0 && strlen($mesaj)>0) {
mysql_query("insert into mesaje set nume='".$nume."',mesaj='".$mesaj."'");
}
else {
}
}
$sql=mysql_query("select * from mesaje order by id desc");
while($row=mysql_fetch_array($sql))
{
$user=$row['nume'];
$msg=$row['mesaj'];
print "<b>".$user.":</b><i>".$msg."<br/>";
}
?>
Cod: Selectaţi tot
function shootbox()
{
print '
<div id="divLogin">
<div class="panelTop">Shootbox</div>
<div class="panel" style="font-size: 14px;">
';
print '
<div id="raspuns"> </div>
<form action="add.php" method="post" name="form1" onsubmit="ajaxrequest(this, \'raspuns\'); return false;">
Numele tau: <input type="text" name="nume" id="nume" size="20" maxlength="33" /><br />
Transmite un mesaj:<br />
<textarea name="mesaj" id="mesaj" cols="15" rows="2"></textarea><br />
<input type="submit" value="Trimite" />
</form>
';
print '
</div>
<div class="panelBottom"></div>
</div>
';
}