简体   繁体   中英

How can I call image from global js?

My global js here :

...\\htdocs\\mysystem\\public\\js\\main.js

The code like this :

$(function(){
    ...
    $('#loading').html('<img class="displayed" src="{{asset("img/loading.gif")}}">');
    ...

I put the image here :

...\\htdocs\\mysystem\\public\\img\\loading.gif

When executes, it not success call the image and no error

How can I solve this problem?

Correct the path to the image like this:

 $(function(){ ... $('#loading').html('<img class="displayed" src="../img/loading.gif">'); ... 

Update: Are the parsers necessary? Within the provided context it is not clear whether you need them.

Try below code, if not worked then let me know the error/cause.

var imagePath = '{{asset("img/loading.gif")}}';
$('#loading').html('<img class="displayed" src="'+imagePath+'">');

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