<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"> <!--
* Creado el 25/08/2011
*
* Autor: Daniel Mora
* Email: danmoracr@gmail.com
*
-->
<!-- Se incluye el framework de JavaScript "JQuery" -->
<script type="text/javascript"> function loadWall(){
//Funcion para cargar el muro
$("#wall").load('wall.php');
//Devuelve el campo mensaje a vacio
$("#msg").val("")
}
//Cuando el documento esta listo carga el muro
$(document).ready(function(){
loadWall();
});
<!-- Le doy un poco de estilo-->
body{
font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
}
label{
color: #808080;
font-size: 11px;
font-weight: bold;
line-height: 30px;
}
#wrapper{
width: 605px;
margin-left: auto;
margin-right: auto;
}
#msg{
border: thin solid #B4BBCD !important;
padding: 5px;
}
#submit{
color: #fff;
font-size: 13px;
background-color: #5B74A8;
background-image: url("background.png");
background-position: 0 -98px;
background-repeat: no-repeat;
border-color: #29447E #29447E #1A356E;
border-style: solid;
border-width: 1px;
cursor: pointer;
display: inline-block;
font-weight: bold;
line-height: normal !important;
padding: 4px 6px 4px;
text-align: center;
text-decoration: none;
vertical-align: top;
white-space: nowrap;
}
#wall{
width: 430px;
min-height: 200px;
border: solid thin #B4BBCD;
margin-top: 10px;
}
#wall ul{
list-style: none;
font-size: 12px;
line-height: 20px;
}
#wall ul #date{
font-style: italic;
font-size: 11px;
color: #ccc;
padding-left: 5px;
}
#loading{
float: left;
position:relative;
top: 10px;
left: 450px;
display: none;
}
<form action="javascript: addMessage();" method="post" id="form_wall"> <input type="text" name="msg" id="msg" maxlength="200" size="50" /> <input type="submit" name="submit" id="submit" value="Share" /> <div id="loading"><img src="loading.gif" /></div>
function addMessage(){
//Tomas los valores del form_wall
var str = $("#form_wall").serialize();
//Si empieza el ajax muesta el loading
$("#loading").ajaxStart(function(){
$("#loading").show();
});
//Cuando termina el ajax oculta el loading
$("#loading").ajaxStop(function(){
$("#loading").hide();
});
//Se envian los datos a url y al completarse se carga el muro
//con la nueva informacion
$.ajax({
url: 'action.php',
data: str,
type: 'post',
error: function(obj, msg, obj2){
alert(msg);
},
success: function(data){
loadWall();
}
});
};