I have written ajax to send search key, I have tried below code
$.ajax({
              method:'GET',
              url:'<?php echo Router::url(['action' => 'product_search']); ?>',
              data:{search:search},
              success: function(data)
              {
                $('.fetch-data').html(data);
              }
});
Then I have received it in product controller like
if ($this->request->is(['get'])) {
             $search   = $this->request->data('search');       
}
Here $search is null. If I use POST in here then it's working fine. How can I receive this data by get method ?
Used below code in product controller
if ($this->request->is(['get'])) {
    $search = $this->request->query('search');       
}
Cookbook > Controllers > Request & Response Objects > Query String Parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With