简体   繁体   中英

Creating href using Laravel 5 with jquery

I am using laravel 5. I am construction a attachments list using jquery.

my file path is /files/myfile.jpg

      $('#attachmentList').empty();
            $.each(response, function(key, val) {
                $('<li><a href="{{ asset('+val.filepath+val.filename+') }}">'
                  +val.filename+'</a></li>').appendTo('#attachmentList');
            });

this creates %7B%7B%asset(files/myfile.jpg)%20%7D%7D url in my address bar.

I need asset url in the hyperlink. How can I make hyperlink in my view.

You need to use the other Blade syntax.

  $('#attachmentList').empty();
        $.each(response, function(key, val) {
            $('<li><a href="{!! asset('+val.filepath+val.filename+') !!}">'
              +val.filename+'</a></li>').appendTo('#attachmentList');
        });

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