Con ajax fue muy facil hacerlo ... aqui el code
Código Javascript :
function ax(){
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 _rg(){
function $(el){return document.getElementById(el);}
$('xdivcarga').innerHTML = "<img src=Imagenes/Carg.gif''>";
ajax=ax();
ajax.open("POST", "envio.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
if(ajax.responseText == 'exito'){
//location.href= ....
} else if(ajax.responseText == 'error'){alert('Ha ocurrido un error. Por favor vuelva a intentarlo.');
location.href = 'index.php';
} else {
$('xdiverrores').innerHTML = ajax.responseText;
}
}}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send("Usuario="+$('campo1').value);
}
bueno un sencillo code pero aora lo quiero hacer con jquery y no puedo
Con jquery encontre un code asi
Código Javascript :
$(document).ready(function() {
$().ajaxStart(function() {
$('#load').show();
$('#respuesta').hide();
}).ajaxStop(function() {
$('#load').hide();
$('#respuesta').fadeIn('slow');
});
$('#form, #miformulario').submit(function() {
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data) {
/* Quiero q muestra la respuesta de la pagina a la que le envie los datos */
/* Mas preciso usar response.Text pero con jquery alguna funcion parecida :S */
if( respuestadelapaginaphp="bien" ) {
/* aki lo ke ago si esta bien */} else {
$('#resultado').html(respuestadelapaginaphp); /* muestro los errores que me dice la pagina osea el action :S /*
}
}
})
return false;
});
})
espero que me ayuden
y de antemano gracias
