There is no PHP function alert
, that’s why your function throws an error and doesn’t proceed with the rest of your code. You have to return something from the LogHit_callback
function using return
(or echo it with echo
) and then alert it with JavaScript, that is add following code to your post
function:
jQuery.post( 'http://www.test.com/wp-admin/admin-ajax.php', data, function( r ) {
alert( r );
});
I believe that this is the correct syntax for post()
. Remember that you can always debug AJAX requests with browser’s developer tools. You will then know exactly what’s going on.