0

In my Ajax I'm receiving data:

$.ajax({
    type: "GET",
    url: Routing.generate('index', {page}),
    success: function (data) {
        console.log(data.data[0].isbn);// print expecting value well
        $('#foo').append("<a href=\"{{ path('foo', { 'id': data.data[0].isbn }) }}\">");
       //Exception: Variable "data" does not exist

This script located in twig file cause:

Exception: Variable "data" does not exist

How to prepare append() content that contains twig and javascript variable?

user6827096
  • 1,186
  • 1
  • 11
  • 26
  • 2
    More appropriate duplicate : http://stackoverflow.com/questions/42537752/twig-in-jquery-not-able-to-read-jquery-variable – Veve Mar 03 '17 at 11:06
  • 1
    check [FOSJsRoutingBundle](https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html) – Matteo Mar 03 '17 at 11:14
  • @Veve thanks, so properly I should prepare entire html in controller/template and receive it in Ajax, but what then controller should return, new Response? ahh never mind... – user6827096 Mar 03 '17 at 11:18
  • 1
    @Matteo I will, thanks. – user6827096 Mar 03 '17 at 11:19

0 Answers0