skip to Main Content

This one is driving me crazy, I’ve tried lots of solutions on stack but can’t seem to get one working with the below.

I’m testing out an ajax filter on some blog posts, but I’m just getting a 400 error "POST /wp-admin/admin-ajax.php 400"

If anybody could shed some light I’d be grateful.

Thank you

enter image description here

2

Answers


  1. I can think only of 3 things:

    1. Your add_actions doesn’t get hit in time, remember that WordPress ajax requests are processed by admin-ajax.php, make sure that your add_action gets called before that
    2. Inside your JS code you used ajax.type = post, that’s wrong. I guess you wanted to use ajax.method = POST and eventually dataType = json. You can see the docs here https://api.jquery.com/jquery.ajax/
    3. Your action doesn’t return any valid data, return some json, some string, something. Its ok to call die() but well, return something maybe ? Since you are expecting something in ajax callback

    P.s. = don’t post code as image, we cannot copy easily from there

    Login or Signup to reply.
  2. Apart from the suggestion posted by @Diego, ajax_url should be the full URL, like https://yourwebsite.com/wp-admin/admin-ajax.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search