Buenas
Tengo un problema con un formulario, el caso es que quería hacer un comet que me encontre por internet pero al ponerle un campo de formulario, nose si se puede hacer de otra forma pero se me actualiza y no me deja escribir es decir pongo para escribir y cuando yevo un rato se actualiza y borra el contenido del textarea nose como se hace de otra forma ni si lo ago bien ya os digo que fue un codigo que encontre ace tiempo este es el codigo.
index.php
Código PHP:
Ver original<?php
if($_POST)
{
header("Edge-control: no-store"); include('config.php');
$notificaciones=mysql_query("select * from messages",$conexion); {
$imgs=mysql_query("select * from usuarios where id='$rs[user_id]'",$conexion); {
echo '<div style="width:50%; background:#CCCCCC; border-bottom:solid; border-bottom-color:#FFFFFF;">';
echo '<img src="'.$im['imagen'].'" height="8%"> ';
echo $rs['estado']."<br>";
echo '<form name="nuevo_empleado1" action="" onSubmit="enviarDatosEmpleado1(); return false" style="margin-left:2%; margin-top:2%;">
<textarea name="nombres1" type="text" cols="50" style="resize: none;"></textarea>
<input type="submit" name="Submit" value="Compartir" />
</form>';
echo '</div>';
}
$coment_de_comen=mysql_query("Select * from coment where id_comentario='$rs[msg_id]'",$conexion); {
echo "abra ssmss";
}
}
}
?>
<html>
<head>
</head>
<body style="">
<div style="border:solid 1px; border-top-color:#666666; width:45%; background-color:#CCCCCC; height:10%;"><form name="nuevo_empleado" action="" onSubmit="enviarDatosEmpleado(); return false" style="margin-left:2%; margin-top:2%;">
<textarea name="nombres" type="text" cols="50" style="resize: none;"></textarea>
<input type="submit" name="Submit" value="Compartir" />
</form></div>
<div id="content">Cargando...</div>
<script type="text/javascript" src="comet.js"></script>
</body>
</html>
comet.js
Código Javascript
:
Ver originalfunction objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function enviarDatosEmpleado(){
//donde se mostrará lo resultados
//valores de los inputs
nom=document.nuevo_empleado.nombres.value;
//instanciamos el objetoAjax
ajax=objetoAjax();
//uso del medotod POST
//archivo que realizará la operacion
//registro.php
ajax.open("POST", "registro.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta cap
//llamar a funcion para limpiar los inputs
LimpiarCampos();
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax.send("nombres="+nom)
}
function LimpiarCampos(){
document.nuevo_empleado.nombres.value="";
document.nuevo_empleado.nombres.focus();
}
function enviarDatosEmpleado1(){
//donde se mostrará lo resultados
//valores de los inputs
nom1=document.nuevo_empleado1.nombres1.value;
//instanciamos el objetoAjax
ajax1=objetoAjax();
//uso del medotod POST
//archivo que realizará la operacion
//registro.php
ajax1.open("POST", "registro.php",true);
ajax1.onreadystatechange=function() {
if (ajax1.readyState==4) {
//mostrar resultados en esta cap
//llamar a funcion para limpiar los inputs
LimpiarCampos1();
}
}
ajax1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax1.send("nombres1"+nom1)
}
function LimpiarCampos1(){
document.nuevo_empleado1.nombres1.value="";
document.nuevo_empleado1.nombres1.focus();
}
var xmlhttp = function()
* * {
* * * * var a;try{a = new XMLHttpRequest();}
* * * * catch(e){try{a = new ActiveXObject('Msxml2.XMLHTTP');}
* * * * catch(e){try{a = new ActiveXObject('Microsoft.XMLHTTP');}
* * * * catch(e){alert('Your browser doesn\'t support ajax');a=false;}
* * * * }}return a;
* * };*
* * window.onload = function()
* * {
* * * * var a = new comet();
* * };*
* * var comet = function()
* * {
* * * * var a = new xmlhttp();
* * * * a.open('post',window.location+"?"+Math.random()+"="+Math.random(), true);
* * * * a.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
* * * * a.onreadystatechange = function()
* * * * {
* * * * * * if(a.readyState == 4)
* * * * * * {
* * * * * * * * document.getElementById('content').innerHTML = a.responseText;
* * * * * * * * window.setTimeout(function(){
* * * * * * * * * * a = new comet();* * * * * * * * * *
* * * * * * * * });
* * * * * * * *
* * * * * * }
* * * * };
* * * * a.send('algo=algo');* * * * * * * *
* * };
y por ultimo este es el registro.php
Código PHP:
Ver original<?php
//Configuracion de la conexion a base de datos
$bd_host = "localhost";
$bd_usuario = "root";
$bd_password = "";
$bd_base = "db";
//variables POST
$nom=$_POST['nombres'];
$nom1=$_POST['nombres1'];
if($nom!='')
{//registra los datos del empleados
$sql="INSERT INTO messages (estado,user_id) VALUES ('$nom','1')";
}
else
{
$sql="INSERT INTO coment (estado) VALUES ('$nom1')";
}
?>
Nose si lo hago bien o que es lo que le pasa pero estaría muy agradecido si me ayudaraís gracias un saludo.