AJAX call using admin-ajax URL is returning 400 bad request

I am attempting to create an AJAX call to pass custom taxonomy into my WP_Query but I am getting 400 (Bad Request). I believe my data array is built correctly so I am not sure what’s causing it. Does anything look off here? Is there a way for me to get a more detailed error of why it is returning error 400?

$.ajax({
    type:'POST',
    url:ajaxUrl,
    data: {
        taxonomy: 'products',
        slug: 'shirts'
    },
    beforeSend:function(xhr){

    },
    success:function(data){
      $('#response').html(data); // insert data
    }
});

I console logged ajaxUrl and I am getting the correct path to admin-ajax.php so I know that’s not the issue. I think it has to have something to do with data.

1 Answer
1

you forgot the “action” key in your data array. With that key you define which function is called from your plugin or function.php File. For more information see the WordPress documentation – AJAX in Plugins

Leave a Comment