0

i have a problem in getting the path of my image in laravel directory in javascript. I already get the image in php but not in javascript here is in my php

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

i tried in my javascript like this and i got error:

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

2 Answers 2

2

you can define like this.you missed curly brace

  $("#feature_img").attr('src',"{{asset('image_files')}}/"+data.product[0].featured_img);
Sign up to request clarification or add additional context in comments.

1 Comment

sorry my mistake :)
1

Get resource path and then use like this

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.