mostrar mensaje usando un formulario + ajax + php
Publicado por sam (7 intervenciones) el 03/03/2015 19:44:42
Hola amigos verán tengo este código con el cual intento enviar "mensajes" mediante un
formulario (archivo 1), a otro archivo php (archivo 2).
Y posteriormente , automáticamente muestre el mensaje enviado en una caja que esta situada justo arriba del formulario (archivo 1).
Pero no me funciona y no se que falla, si me pudieran ayudar les estaria muy agradecido.
Este es el codigo
archivo 1:
archivo 2 llamado "historial_mensajes.php"
formulario (archivo 1), a otro archivo php (archivo 2).
Y posteriormente , automáticamente muestre el mensaje enviado en una caja que esta situada justo arriba del formulario (archivo 1).
Pero no me funciona y no se que falla, si me pudieran ayudar les estaria muy agradecido.
Este es el codigo
archivo 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<script>
$("#btn_enviar_mensaje").click(function(){
$.ajax(
{
url: "php/historial_mensajes.php",
type: 'post',
data: data,
success: function(result){
$("#historial_mensajes").html(result);
}
}
);
});
});
</script>
<html>
<div id="historial_mensajes"></div>
<form>
<input type="text" name="mensaje" autofocus class="inputstyle" id="mensaje" placeholder="Mi mensaje"/>
<button id="btn_enviar_mensaje">Enviar mensaje</button>
</form>
</html>
archivo 2 llamado "historial_mensajes.php"
1
2
3
4
5
<?php
$mensaje = trim(($_POST['mensaje']));
echo 'Mensaje: ' . $mensaje . '<br/><br/>';
?>
Valora esta pregunta


0