Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using ajax in wordpress theme,but ir response -1,why? how to correct this?

function videospage(cnt)
{
    var pageno=cnt;

    jQuery.ajax({  
        type: "POST",  
        url: "<?php echo admin_url('admin-ajax.php'); ?>",  
        data: {  
            action: "myajaxpagination",  
            pageno: pageno,  
        },  
        success: function(datas){  
            alert(datas);  
        },  
        error: function(MLHttpRequest, textStatus, errorThrown){  
            alert(errorThrown);  
        }  
    });  

}

add_action('wp_ajax_myajaxpagination', 'my_action_pagination');  
function my_action_pagination()
{
    $pageno=$_REQUEST['pageno'];
    echo $pageno;
    die();
}
share|improve this question

1 Answer 1

Pay attention that your ajax request will work only for logged in users. If you want to make it working for everybody, you have to add one more action wp_ajax_nopriv_myajaxpagination with the same hook:

function videospage(cnt)
{
    var pageno=cnt;

    jQuery.ajax({  
        type: "POST",  
        url: "<?php echo admin_url('admin-ajax.php'); ?>",  
        data: {  
            action: "myajaxpagination",  
            pageno: pageno,  
        },  
        success: function(datas){  
            alert(datas);  
        },  
        error: function(MLHttpRequest, textStatus, errorThrown){  
            alert(errorThrown);  
        }  
    });  

}

add_action('wp_ajax_myajaxpagination', 'my_action_pagination');  
add_action('wp_ajax_nopriv_myajaxpagination', 'my_action_pagination');
function my_action_pagination()
{
    $pageno=$_REQUEST['pageno'];
    echo $pageno;
    die();
}

Read more about AJAX in WordPress.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.