Skip to content

Instantly share code, notes, and snippets.

@jsakhil
Forked from vishnusomanus/wp ajax
Created August 29, 2017 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsakhil/27f14ba1ea0a9dbab57b482d71f94298 to your computer and use it in GitHub Desktop.
Save jsakhil/27f14ba1ea0a9dbab57b482d71f94298 to your computer and use it in GitHub Desktop.
var data = {
action: 'image_color',
id: 1234
}
//jQuery
jQuery.ajax(
{
url: " http://domain.com/wp-admin/admin-ajax.php",
type: "POST",
data: data,
success: function (result) {
alert('success');
}
});
//in function.php
add_action( 'wp_ajax_function_name', 'function_name' );
add_action( 'wp_ajax_nopriv_function_name', 'function_name' );
function function_name() {
echo "string";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment