Answer the question
In order to leave comments, you need to log in
Why write url: admin-ajax.php?
Hello!
I'm learning ajax in Wordpress.
In some examples I see this code
$.ajax({
url: "/wp-admin/admin-ajax.php",
method: 'post',
Answer the question
In order to leave comments, you need to log in
Here is the answer to your question and to all subsequent ones on this topic.
Your js sends data to the handler file which is the entry point. Think of it as an API endpoint . Because functions.php
you can't send a request for a file, it's an include. But this /wp-admin/admin-ajax.php
is not an include, a slightly lighter version of the whole WordPress is raised there, which is designed solely to accept your sent data, determine which action you want to use, and through this action pass the received data to the handler that hangs on this action. And now functions.php
you are on this action in the format wp_ajax_{$action}
and wp_ajax_nopriv_{$action}
connect your handler, which will accept the sent data, do everything you need with it and return the answer, which in turn /wp-admin/admin-ajax.php
will return back to your js.
According to the link Anatoly Pychevmore details with examples. In general, open the file itself in the editor /wp-admin/admin-ajax.php
and some questions will disappear by themselves.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question