问题
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