Está en la página 1de 3

$(document).ready(function(){ $("#id").click(function(){ $.

ajax({ data: "parametro1=valor1&parametro2=valor2", type: "GET", dataType: "json", url: "url_archivo_php", success: function(data){ alguna_funcion_a_realizar_segun_resultados; } }); }); }); *********** <script src="js/jquery-latest.js" type="text/javascript"></script> <script src="js/jquery.form.js" type="text/javascript"></script> <script type="text/javascript"> // esperamos que el DOM cargue $(document).ready(function() { // definimos las opciones del plugin AJAX FORM var opciones= { beforeSubmit: mostrarLoader, //funcion que se eje cuta antes de enviar el form success: mostrarRespuesta //funcion que se ejecut a una vez enviado el formulario }; //asignamos el plugin ajaxForm al formulario myForm y le pasamos la s opciones $('#myForm').ajaxForm(opciones) ; //lugar donde defino las funciones que utilizo dentro de "opciones" function mostrarLoader(){ $(#loader_gif).fadeIn("slow"); //muestro el loader de ajax }; function mostrarRespuesta (responseText){ alert("Mensaje enviado: "+responseText); //responseT ext es lo que devuelve la pgina contacto.php. Si en contacto.php hacemos echo "Ho la" , la variable responseText = "Hola" . Aca hago un alert con el valor de resp onse text $("#loader_gif").fadeOut("slow"); // Hago desaparecer el loader de ajax $("#ajax_loader").append("<br>Mensaje: "+responseText) ; // Aca utilizo la funcin append de JQuery para aadir el responseText dentro del div "ajax_loader" }; }); </script> ************ 01.$(document).ready(function(){ 02.$('#submit').click(function() { 03. 04.$('#waiting').show(500);

05.$('#demoForm').hide(0); 06.$('#message').hide(0); 07. 08.$.ajax({ 09.type : 'POST', 10.url : 'post.php', 11.dataType : 'json', 12.data: { 13.email : $('#email').val() 14.}, 15.success : function(data){ 16.$('#waiting').hide(500); 17.$('#message').removeClass().addClass((data.error === true) ? 'error' : 'succe ss') 18..text(data.msg).show(500); 19.if (data.error === true) 20.$('#demoForm').show(500); 21.}, 22.error : function(XMLHttpRequest, textStatus, errorThrown) { 23.$('#waiting').hide(500); 24.$('#message').removeClass().addClass('error') 25..text('There was an error.').show(500); 26.$('#demoForm').show(500); 27.} 28.}); 29. 30.return false; 31.}); 32.}); ********** <script type="text/javascript"><br> $(document).ready(function() { $(".boton").click(function(event) { $("#caja").load('carga.html',aviso()); }); }); function aviso(){ alert('La solicitud ha sido procesada'); } </script> *****************ESTE******************* $("#form1").submit(function(){ if(checkCommentsForm()){ targetDiv.show('fast'); //send to test.php $.ajax({ type: "POST", url: 'test.php', data: "name="+userName.val()+"&email="+userEmail.val()+"&txt="+u serTxt.val(), complete: function(data){ //print results as appended targetDiv.append(data.responseText); //print result in targetDiv //targetDiv.html(data.responseText);

} }); } else alert("Please fill required fields!"); return false; }); });

También podría gustarte