Created
November 10, 2021 09:26
-
-
Save arafatjamil01/8ae0238412414ba0239add2821f36850 to your computer and use it in GitHub Desktop.
WordPress AJAX actions
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
Tasks to do: | |
---------------- | |
> use actions wp_ajax_(action_name_here) & wp_ajax_nopriv_(action_name_here) to initiate functions | |
> you can use the same or different functions for the same purpose | |
> then define the ajax js file, use jQuery if needed, wordpress has jquery inside already | |
> use wp_localize_script('js_file_handle','name_of_object',[ 'key' => 'value ] | |
> the key value pair can be given primarily the wordpress ajax url admin_url('admin-ajax.php') | |
> define the ajax action name in the jquery, exactly like the action name in wp_ajax_(action_name_here) hook. | |
> write the function as needed. e.g - beforeSend, success keys in jQuery or state change in vanilla JS | |
> according to the defined actions, wordPress should just work fine. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment