Home > Blockchain >  admin-ajax.php 400 error when filtering blog posts
admin-ajax.php 400 error when filtering blog posts

Time:09-30

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

CodePudding user response:

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

CodePudding user response:

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

  • Related