$.ajax() function is what we’re using here. There are special functions for post and get methods but I prefer using this function because of its flexibility. You can read about all the parameters in the jQuery Documentation.
Using the url parameter we pass the URL of the script we want to send data to. This should be the admin-ajax.php file which can be found in the wp-admin directory. We defined this above via the wp_localize_script() function.
The type is set to post. We could also use get, our query is not too sensitive but I prefer to post data unless the user needs access to the parameters.
The data parameter is an object which contains the data you want to pass. In our case I will be able to access a $_POST['action'] variable, the value of which would be ajax_pagination. You can pass as many as your application requires of course.
successparameter is a function which alerts the result of our AJAX call. We’ll make this a bit fancier below, for now this is sufficient for testing. If you try clicking on a link now it actually works but won’t be very useful since we haven’t defined the server side code. In fact, what you should see alerted is 0.
So why does this happen? When I said “we haven’t defined server side code,” I wasn’t entirely truthful. We haven’t, but WordPress has. There is some content in the admin-ajax.php file we are using. If you take a look at the source code of that file you should see that the script uses die( '0' ) in a couple of cases.
If we don’t supply an action the admin-ajax.php script dies and returns 0. If we do supply an action but we don’t hook into the required WordPress hooks nothing happens and at the very end of the file we die again, returning 0. In conclusion we are already communicating with the server.
Communicating With WordPress
To get a meaningful answer from WordPress we need to define some WordPress actions. This is done using a set pattern. Let’s dive in by continuing our example in the functions file of our theme:Resultado de los ganadores de la lotería de visas 2021
A partir del 6 de junio de 2020 se darán a conocer los ganadores de la lotería de visas de Estados Unidos 2021 (DV-2021), para...
Leer másInformación sobre el cambio de dirección
Cambiar su dirección con el Servicio Postal de Estados Unidos (USPS, por sus siglas en inglés) no cambiará su dirección con USCIS. Por favor actualice su información tanto...
Leer más¿Quiénes califican para una extensión de estadía con visa turista?
La extensión de estadía es para algo temporal, como un asunto médico, una recuperación, no poder volar, un percance familiar, una situación donde vas a regresar pero...
Leer más¿Qué debes hacer si eres indocumentado y te detiene una redada migratoria?
Las órdenes ejecutivas migratorias del presidente Donald Trump han puesto al borde de la deportación a los 11 millones de inmigrantes indocumentados que viven en...
Leer másCambia el examen de la ciudadanía y nuevas faltas causan denegación
Los residentes permanentes que quieran ser ciudadanos por naturalización a partir de diciembre del 2020, se someterán a una prueba de ciudadanía diferente, tras una revisión del examen...
Leer másCómo prepararse para su entrevista de asilo
Usted debe traer consigo el día de su entrevista:1. Un documento que lo identifique, incluyendo:a. Cualquier pasaporte en su poderb. Otros documentos de viaje o...
Leer másUSCIS anuncia formalmente la implementación del proceso de registro electrónico H-1B y el plazo de dicho registro
USCIS abrirá un periodo inicial de registro que transcurrirá del 1 al 20 de marzo de 2020, para las cantidades asignadas de visas H-1B del...
Leer más¿Conoces alguna clínica de salud gratuita?
Estas clínicas de salud gratuitas independientes proporcionan atención primaria y otros servicios ambulatorios a pacientes sin seguro que cumplan con las pautas de necesidad financiera:Good Health Clinic91555 Overseas Highway, Tavernier305-853-1788Horario: Miércoles, jueves y viernes...
Leer más