Use ajax in cakephp 3

0

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';
    $this->set('sizes',$query_sizes);
    }

}

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

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

But I get this error

toolbar.js:90 GET http://192.168.1.26:8080/nuevostyle/Advertisements/%3C?php%20echo%20Router:…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
source

1 answer

1

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

 url: "http://192.168.1.26:8080/nuevostyle/Advertisements/listsize"
    
answered by 29.08.2016 в 19:58