Foros del Web » Programando para Internet » Jquery »

Animacion mientras envía formulario

Estas en el tema de Animacion mientras envía formulario en el foro de Jquery en Foros del Web. Hola! Espero puedan ayudarme, tengo el siguiente codigo en jsp: <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/JavaScript" src="js/jquery-1.7.js"></script> <script ...
  #1 (permalink)  
Antiguo 24/02/2013, 00:28
Avatar de garcia2013  
Fecha de Ingreso: febrero-2013
Mensajes: 1
Antigüedad: 11 años, 2 meses
Puntos: 0
Pregunta Animacion mientras envía formulario

Hola! Espero puedan ayudarme, tengo el siguiente codigo en jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/JavaScript" src="js/jquery-1.7.js"></script>
<script type="text/JavaScript">
$(document).ready(function(){
$("span#numeroPalabras").text("Número de palabras: ");

$("#send").click(function(){
var texto = $("#texto").val();
$.ajax({
type: "POST",
url: "cuenta.jsp",
data: "texto=" + texto,
success: function(msg){
$("span#resultado").text(msg);
},
error: function(xml, msg){
$("span#resultado").text("Error");
}
});
});
});
</script>

<title>JSP y JQuery</title>

<script>
window.onload = detectarCarga;
function detectarCarga(){
document.getElementById("carga").style.display="no ne";
}
</script>
<script>
function carga() {
setTimeout("document.getElementById('carga').style . display = 'none'", 10000);}
window.onload = carga;
</script>

</head>
<body>


<div id="carga">
<img src="images/cargando.gif" />
</div>


<p> <span id="numeroPalabras"></span>
<span id="resultado"></span>
</p>
<div>
<label> Introduce el texto: </label>
<br> <br>
<textarea id="texto" cols="40" rows="7"></textarea>
<br> <br>
<input id="send" type="button" value="Enviar" click="detectarCarga()"/>



</body>

</html>


Al ejecutarlo me genera la imagen de cargando arriba del formulario, la imagen dura el tiempo establecido (10000 milisegundos), pero lo que necesito es que la imagen aparezca cuando se le da click al boton enviar, y se espere el tiempo asignado antes de procesar la informacion.

Gracias!
  #2 (permalink)  
Antiguo 24/02/2013, 09:01
Avatar de rottenp4nx  
Fecha de Ingreso: octubre-2012
Ubicación: Santiago
Mensajes: 417
Antigüedad: 11 años, 6 meses
Puntos: 36
Respuesta: Animacion mientras envía formulario

Primero al div carga colocale la propiedad css display en none, como default, para que funcione el siguiente código

Código Javascript:
Ver original
  1. $("#send").click(function(){
  2. var texto = $("#texto").val();
  3. $.ajax({
  4. type: "POST",
  5. url: "cuenta.jsp",
  6. data: "texto=" + texto,
  7. beforeSend: function(){
  8.    $("#carga").show("slow");
  9. },
  10. success: function(msg){
  11. $("#carga").hide("slow",function(){
  12. $("span#resultado").text(msg);
  13. });
  14. },
  15. error: function(xml, msg){
  16. $("span#resultado").text("Error");
  17. }
  18. });
  19. });
  20. });
  21. </script>

Con ese script hará lo que necesitas, saludos!

PD: No uses colores para el código, para poder leerlo bien
  #3 (permalink)  
Antiguo 24/02/2013, 13:30
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Animacion mientras envía formulario

Podrías por favor poner el código terminado si lo has resuelto?
Un saludo
  #4 (permalink)  
Antiguo 24/02/2013, 14:03
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Animacion mientras envía formulario

A ver si te vale este ejemplo:
Código PHP:
<html>
<
head>
<
title>Untitled</title>
<
style>
#loading_oculto{
z-index:99;
position:absolute;
top:50%;
left:50%;
margin-left:-117px;
margin-top:-117px;
visibility:hidden;
}

</
style>
</
head>

<
body>
<
form action="" id="ss" name="ss" method="post">
Nombre:<input type="text" name="e" /><br />
Apellidos:<input type="text" name="ww" />
<
input type="submit" name="eeeee" value="Enviar" onclick="document.getElementById('loading_oculto').style.visibility='visible';" />
</
form>
<
div id="loading_oculto"><img src="imagenes/ajax-loader.gif" /></div>

</
body>
</
html
Saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:00.