Ell Ell - 7 months ago 14
Javascript Question

Laravel Jquery: URLs are being read as "

I'm making an app with Laravel. I have a variable called dataActivity, and I want to use this as an image url. Since Laravel uses

{{ URL::asset('path') }}
to make a link, I did this:

$('.box').css("background-image", "url('{{ URL::asset('icons/"+dataActivity+".png')}}')");


However, the not found error outputs the link as
http://localhost:8000/pictures/"+dataActivity+".png


As you can see, there are
&quot
s where there shouldn't be. Any idea how to fix this?

Answer

use

$('.box').css("background-image", "url('{!! URL::asset('icons/"+dataActivity+".png')!!}')");

instead of

$('.box').css("background-image", "url('{{ URL::asset('icons/"+dataActivity+".png')}}')");
Comments