Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp 3 : How to receive get request data?

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 ?

like image 509
Satu Sultana Avatar asked Sep 07 '25 04:09

Satu Sultana


1 Answers

Used below code in product controller

if ($this->request->is(['get'])) {
    $search = $this->request->query('search');       
}

Cookbook > Controllers > Request & Response Objects > Query String Parameters

like image 129
Balkrushna Maheta Avatar answered Sep 10 '25 03:09

Balkrushna Maheta