-
-
Save pietromalerba/6c12e4728c6f44f1cf2b to your computer and use it in GitHub Desktop.
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
jQuery.ajax({ | |
url: '/wp-admin/admin-ajax.php', | |
type: 'GET',//POST, JSON, XML | |
dataType: 'html', | |
data: ({ | |
action: 'MY_AJAX_FUNCTION', | |
state: state, | |
}), | |
success: function(data){ | |
if (data){ | |
} | |
else | |
{ | |
} | |
} | |
}); | |
//Put this in function.php | |
wp_localize_script( 'ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); | |
function MY_AJAX_FUNCTION(){ | |
//doing something here | |
die($results); | |
} | |
add_action('wp_ajax_MY_AJAX_FUNCTION', 'MY_AJAX_FUNCTION'); | |
add_action('wp_ajax_nopriv_MY_AJAX_FUNCTION', 'MY_AJAX_FUNCTION'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment