Stuck at Creating an AJAX Call based on this article https://premium.wpmudev.org/blog/load-posts-aja

Hello,
I'm trying to replicate this AJAX article tutorial. https://premium.wpmudev.org/blog/load-posts-ajax/

The thing is under Creating an AJAX Call, I don't see the alert 0 message. When I check console, this error came up.

POST https://iceiceicy.com/wingwah/wp-admin/admin-ajax.php 400 ()
send @ jquery.js:4
ajax @ jquery.js:4
(anonymous) @ ajax-pagination.js:4
dispatch @ jquery.js:3
r.handle @ jquery.js:3

Do you guys have any idea why?

  • Ash

    Hello Nazrin Noorzan

    400 request is mainly server side error. You need to check the followings:
    1. Consult with your host if your server any firewall block for that URL
    2. If you have any security plugin, disable those
    3. Enable debug mode and check if there is any error? To enable debug mode please go to wp-config.php and change

    define( 'WP_DEBUG', false );

    to

    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    define( 'WP_DEBUG_LOG', true );

    Now run the ajax again. That may create a file called debug.log inside wp-content folder. Open that file, check the very bottom and you will see the latest errors. Please send me those.

    Have a nice day!

    Cheers,
    Ash

  • Nazrin Noorzan

    Hello,

    Sorry for the late reply. But nevermind about that, I kept continue the tutorial and manage to get it works.

    btw, I've a WordPress site with WooCommerce plugin. I've created some custom HTML links that goes to each product tags. Now I want the product result show without going to the respective page.

    Is the implementation roughly like the tutorial? What are the main keys/information that I need to gather?

  • Ash

    Hello Nazrin Noorzan

    It's always recommended to create separate thread for separate issues, this helps us to provide better and organized support :slight_smile:

    I've created some custom HTML links that goes to each product tags. Now I want the product result show without going to the respective page.

    Do you mean, when someone clicks on the tag, then you want to show the product result on the same page instead of respective product tag page?

    If so, then yes, you would need ajax and that's almost similar to the article. But in the php code you have to write query to fetch the product for a specific tag. Or you can try a woocommerce ajax filter plugin like this: https://wordpress.org/plugins/woocommerce-ajax-filters/ There are more in the wp.org repo if you search for :slight_smile:

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.