Cakephp 3:如何接收获取请求数据? [英] Cakephp 3 : How to receive get request data?

查看:126
本文介绍了Cakephp 3:如何接收获取请求数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了ajax来发送搜索关键字,我试过下面的代码

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');       
}

这里 $ search 为null。如果我在这里使用 POST ,它的工作正常。如何通过get方法接收此数据?

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&响应对象>查询字符串参数

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

这篇关于Cakephp 3:如何接收获取请求数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆