0
 var id_person_value = 4;

$('#message').load("{{ path('MyBundle_ajax_modal_vote', {'id_person' :"+id_person_value+"})   }}", function() {//..

It should return

$('#message').load("{{ path('MyBundle_ajax_modal_vote', {'id_person' : 4 })   }}", function() {//..

But this returns me : http://mywebsite.com/app_dev.php/+id_person_value+

How could I inject the value correctly?

Thanks a lot for your help!

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
Reveclair
  • 2,399
  • 7
  • 37
  • 59

3 Answers3

1

You can make use of escape characters such as \' to insert single quote inside the string and \" for double quotes

Rohini
  • 37
  • 12
1

Instead of concatenating things together, which is tedious and error prone, try a formatting function, similar to printf or format in other languages:

str = format("{{ path('MyBundle_ajax_modal_vote', {'id_person' : {0} }) }}", 4)

Unfortunately, there's no such builtin in Javascript, but it's quite easy to write:

function format(str) {
    var args = [].slice.call(arguments, 1);
    return str.replace(/{(\d+)}/g, function($0, $1) {
        return args[$1]
    })
}

See JavaScript equivalent of Python's format() function? for more implementations.

Community
  • 1
  • 1
georg
  • 211,518
  • 52
  • 313
  • 390
0

use simple double quotes to start and end of string "". If you want to include any quote or double quote in your string use escape character \ before quote eg you want string as s= hello"world then s= "hello\""+"World" or s="hello"+"\"" + "world"

deepak
  • 199
  • 2
  • 9