0

I'm working on a WordPress Theme (create a custom theme) and using AJAX as pagination for my Custom Posts.

So I'm going to load pages with AJAX but the problem is when I click for next page, instead of next page it's returning the home page.

Now I'm going to make it easier with a simple sample, if you can help me to call HELLO query in sample below, I will fix the whole codes with your path.

Here is my HELLO target for example (we should call it):

This is my code in functions.php

add_action("wp_ajax_check_user", "check_user");
add_action("wp_ajax_nopriv_check_user", "check_user");

function check_user() {

    echo 'hello';
    die();
}

And this is my code to call "HELLO" in some page:

$.ajax({
        type: 'POST',
        url: "<?php echo admin_url('admin-ajax.php') ?>",
        data: { 
            'action': 'check_user'
            },
        success : function(data) {
            alert(data); //FOR DEBUG
        }

    });

So I can't call hello and instead I see my home page.


UPDATE: @face

this is my sample page and you can see the results after click on next page or page 2:

here is my sample page

at the bottom of the page please try to go next page or page 2. i made the results as a message box.

3
  • Can you paste the result of your ajax call please?
    – FaCE
    Sep 26, 2016 at 11:29
  • @FaCE original post updatet. please take a look Sep 26, 2016 at 13:45
  • Ok, I've had a look -- what plugins are you using? For a start your URLs aren't ending with trailing slashes, and when I go to yoursamplepage.com/wp-admin/ I get your homepage returned -- try disabling any plugins that affect your permalinks and try your script again.
    – FaCE
    Sep 26, 2016 at 16:19

1 Answer 1

0

Is your "next" Button an HTML "a"-Element? Please add a little bit more of your code. How do you call your $.ajax - Method?

Am I right that you call it sometings like this:

$("#elementid").on("click", function() {
   $.ajax({....});
}

When I am right and you use an a-Element. Add the following after the "click" method:

$("#elementid").on("click", function(e) {
    e.preventDefault();
    $.ajax({....});
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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