2017-09-13 21 views
0

我有一個問題,在JavaScript中獲取我的圖像在laravel目錄中的路徑。我已經得到的圖像在PHP,但不是在JavaScript這裏是我的PHPlaravel路徑錯誤設置圖像源在javascript

<img src="{{ asset('image_files/' . $product->featured_img) }}" /> 

我在我的JavaScript這樣的嘗試,我得到了錯誤:

$("#feature_img").attr('src',asset('image_files/'+data.product[0].featured_img)) 

回答

1

你可以這樣定義this.you錯過大括號

$("#feature_img").attr('src',"{{asset('image_files')}}/"+data.product[0].featured_img); 
+0

ya.wait iwill編輯我的答案 – iCoders

+0

ya.you是正確的,你可以刪除裏面/,如果它的肝臟請標記爲接受 – iCoders

+0

對不起我的錯誤:) – iCoders

1

獲取資源的路徑,然後用這樣的

var path = "{{ resource_path() }}"; 

$("#feature_img").attr('src',path +"/asset/image_files/"+data.product[0].featured_img);