WordPress.org

Forums

[resolved] Plugin ajax call to wp-ajax.php in admin page returning 0 (4 posts)

  1. viter-z-bayraku
    Member
    Posted 4 years ago #

    My code is:

    jQuery.ajax({
    url: "<?php echo admin_url('admin-ajax.php'); ?>",
    type: 'POST',
    data: {
    action: 'stravyfuncajax'
    },
    dataType: 'html',
    success: function(response) {						alert(response);
    }
    add_action('wp_ajax_stravyfuncajax', 'testfunc11');
    add_action('wp_ajax_nopriv_stravyfuncajax', 'testfunc11');
    
    function testfunc11() {
    echo "2";
    die();
    }

    Please help. Thanks!

  2. yannou974
    Member
    Posted 4 years ago #

    hi

    did u debug it ?
    i've the same problem here ...

    thanks

  3. viter-z-bayraku
    Member
    Posted 4 years ago #

    I dont remember how i fixed it, but now this code are working.

    jQuery(document).ready(function(){
    		jQuery("#testbutton").click(function(){
    			 jQuery.ajax({
    				url: "<?php echo admin_url('admin-ajax.php'); ?>",
    				type: 'POST',
    				data: {
    				action: 'stravyfuncajax22'
    				},
    				dataType: 'html',
    				success: function(response) {
    				alert(response);
    				}
    			});
    		});	
    
    	});

    and code:

    add_action('wp_ajax_stravyfuncajax22', 'testfunc11');
    add_action('wp_ajax_nopriv_stravyfuncajax22', 'testfunc11');
    
    function testfunc11() {
    echo "2";
    die();
    }
  4. yannou974
    Member
    Posted 4 years ago #

    Hi Viter,

    Thanks veru much, i'll try it

Topic Closed

This topic has been closed to new replies.

About this Topic