Created
December 1, 2015 16:05
-
-
Save pablocattaneo/c500841872555766cead to your computer and use it in GitHub Desktop.
Mi primer ajax Jquery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title of the document</title> | |
<script src="jquery-1.11.3.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$.post( "request.php",function(data) { // 1-el sgundo parámetro, function es el callback cuando el request da success el parámetro dentro del mismo, data es la todo el contenido del sitio | |
$('.ver').click(function(event) { | |
event.preventDefault(); | |
if($(data).hasClass('valido')){ // chequeamos si el contenido que trae ajax tiene la clase valido ya que del lado de php se valida el formulario si pasa la validación se muestra un elemento con la clase valido en caso contrario se muetra otro elemento con la clase no pasó la validación | |
$(".result").html("el formulario valido"); | |
}else{ | |
$(".result").html("el NO formulario valido"); | |
} | |
}); // Click | |
}); // Post | |
}); // Document | |
</script> | |
</head> | |
<body> | |
<a href="" class="ver">ver</a> | |
<p>Content of the document......</p> | |
<p class="result"></p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if('paso-la-validación'){ | |
<p class="valido">paso la validación</p> | |
}else{ | |
<p class="novalido">No paso la validación</p> | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment