Last active
October 27, 2015 03:41
-
-
Save rnaffer/7c1bcc5ddcf47501411a to your computer and use it in GitHub Desktop.
Consideraciones básicas de Ajax
This file contains 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
/* Explicación de los parámetros básicos de ajax | |
* Puede almacenarse en una variable o llamarse directamente. | |
* method: método usado para la solicitud. "POST", "GET", "PUT". | |
* data: incluye datos en el procedimiento. | |
* dataType: establece el formato del archivo que sera devuelto "xml, json, jsonp, script, text o html" | |
* context: el objeto descrito sera el contexto de los callback relacionados con la solicitud. | |
*/ | |
var request = $.ajax({ | |
url: "script.php", | |
method: "POST", | |
data: { id : menuId }, | |
dataType: "html", | |
context: document.body | |
}); | |
request.done(function( parametro ) { | |
// Do stuff | |
}); | |
$.ajax({ | |
url: "/api/direccion", | |
method: "GET" | |
}) | |
.done(function( parametro ) { | |
// Si todo sale bien | |
}) | |
.fail(function( parametro ) { | |
// Si algo sale mal | |
}) | |
.always(function( parametro ) { | |
// Si la solicitud fue resuelta o rechazada | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment