plugins – Jquery POST Ajax Return null data in wordpress

Question

I really need help on this one. I’ve been looking at it for hours and been getting nowehere. I am working with ajax in WordPress and this is kind of my first time doing so.

It’s always return null data

This is Jquery Code:

<script>
  (function($){

    $(document).ready(function(){
      
      $(document).on('change', '#myform', function(e) {

        e.preventDefault();

        var data = $(this).serialize();

        $.ajax({
          url: "<?php echo admin_url('admin-ajax.php'); ?>",
          data: {action:'myaction', data:data},
          type: 'post',
          success: function(result) {
            $('.products').html(result);
          },
          error: function(result) {
            console.warn(result)
          },
        });

      });
    });
  })(jQuery);
</script>

And this is my PHP Code to get my data:

  $categories = $_POST['color']; 

  var_dump($categories);

when I do var dump I just see null data so how can fix the problem, please?

Image from console

0
Ahmed java 5 months 2022-02-07T17:19:58-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse