title: How can I use a dynamically generated path in JS to generate a URL for my <img>'s src attribute in my view.blade.php?
body: <p>In my <code>$.ajax()</code> from my JQuery script written inline in my <code>blade.php</code> view file, I have received a path to an image file (relative to public folder, like <code>/thumbnails/87991.png</code>) as a response. Say the response in <code>success()</code> of <code>$.ajax()</code> is stored in variable <code>dataReturned</code>.</p>
  <pre><code>console.log('dataReturned:'+dataReturned);
  // Prints the correct '/thumbnails/87991.png'
  </code></pre>
  <p>So in the <code>success()</code> of <code>$.ajax()</code>, I want to set that path as the value of a <code>src</code> attribute for an <code>&lt;img&gt;</code> on that page. For that, I want to generate a valid URL by passing it to the Laravel's <em><code>url()</code></em> helper. Like as follows.</p>
  <pre class="lang-js prettyprint-override"><code>var thumbnailPhotoPathOnServer = &quot;{{url(dataReturned)}}&quot;; 
  var thumbnailPhotoPathOnServer = &quot;{{url('dataReturned')}}&quot;; // I know it makes it a string but i still tried it out of desperation =(
  var thumbnailPhotoPathOnServer = &quot;@php echo url(dataReturned); @endphp&quot;;
  </code></pre>
  <p>I have tried all these statements but I keep getting</p>
  <blockquote>
  <p>Use of undefined constant dataReturned - assumed 'dataReturned' (this will throw an Error in a future version of PHP)</p>
  </blockquote>
  <p>So that question is that what am I missing here and what should I do about it?</p>