Use ajax in cakephp 3


Hi everyone, how are you going to see I have a function inside my controller AdvertisementsController something like that

public function listsize($article = null) {
    if ($this->request->is('get')) {
        $query_sizes = $this->ArticlesSizes->find('list',['conditions'=>['id_article' => $article]]);
    $this->layout = 'ajax';


the result of it I want to take it in a function of ajax in jquery something like that

   var id = $(this).val();
        type: 'GET',
        async: true,
        cache: false,
        url: "<?php echo Router::Url(['controller' =>'Advertisements','Action'=>'listsize'])?>",
        success: function (data) {

But I get this error

toolbar.js:90 GET…dvertisements%27,%27Action%27=%3E%27listsize%27])?%3E&id=2&_=1472490466544 404 (Not Found)

in the console I do not know if I'm doing well or I'm missing Thanks for the help

asked by Jonathan Cunza 29.08.2016 в 19:40

1 answer


Apparently in your js file in the url attribute is not interpreting the php code, try to put the route directly, example:

 url: ""
answered by 29.08.2016 в 19:58