Cakephp 3 : How to receive get request data?

喜欢而已 提交于 2019-12-10 10:25:06

问题


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 ?


回答1:


Used below code in product controller

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

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



来源:https://stackoverflow.com/questions/33142015/cakephp-3-how-to-receive-get-request-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!