I was using symfony2 and in my javascript file chooselist.js.twig , I need to append something to my html page, and I need to get a path of my image. I tried my code like this, but it didn't work.
$.ajax({
type: 'POST',
url: 'listmore',
data: btnArr,
success: function(msg){
var ret = $.parseJSON(msg);
var str="";
for(var i=0; i<ret.itemTab.length; i++) {
str +="<a href=\"#\"><li>\
<p id=\"peopleresume"+jid+"_"+ret.itemTab[i]["pid"]+"\">"+ret.itemTab[i]["pname"]+"</p>\
<img src=\"{{asset('img/video.png')}}\"/>\
<div class=\"clear\"></div>\
<div class=\"listInfo\" id="+ret.itemTab[i]["rid"]+">"+ret.itemTab[i]["introduction"]+"</div>\
</li></a>";
}
tempId.find(".ListBlock").append(str);
},
error: function(XmlHttpRequest,textStatus, errorThrown){
alert ("failed! "+XmlHttpRequest.responseText);
}
});
in my code {{asset('img/video.png')}}, it doesn't work. What should I do to make it work?
I think it should be {{ asset('bundles/yourbundle/images/video.png') }}
Furthermore, make sure you installed your assets by running the following command:
php app/console assets:install
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.