简体   繁体   中英

passing more than one javascript parameter to a PHP file with twig

I want to pass three parameter to a PHP file with twig path() . I found a solution in this question . It works fine with one value, but with two values it puts & instead of & in the URL. this is the code I used:

var route = "{{ path('dashboardTable', { 'data1': 'fistData', 'data2' : 'secondData})}}";
route = route.replace('firstData',  D1);
route = route.replace('secondData',  D2 );
window.location.href = route;

It sets the firstData and socondData and the URL will be this:

http://localhost:8000/dashboard/table?data1=Low&data2=deactive

but because of the & it's not working. how can I change & to & ?

the funny point is that if I put the amp; before data2 in my get request like below, it works fine!

$data2 = $_GET["amp;data2];

According to DaveCoast comment I added raw in the code like below and it solved the problem .

var route = "{{ path('dashboardTable', { 'data1': 'fistData', 'data2' : 'secondData})|raw}}";
route = route.replace('firstData',  D1);
route = route.replace('secondData',  D2 );
window.location.href = route;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM