Home > Blockchain >  How to pass data to aherf in laravel blade from js variable
How to pass data to aherf in laravel blade from js variable

Time:02-03

I sent a ajax request to get data from controller with json format. something like this-

return response()->json($data);

I received the response from laravel view with a variable like this-

var rpr_data_id = response.id;

Now I want to pass this variable to one of my data. Button is written in this format-

<a href="{{url('rpr/')}}"> <button>send</button></a>

Question: how to pass the js variable in laravel blade anchor tag?

CodePudding user response:

You can use the attr() method for that.

Assuming your link can be easily selected:

<a id="your-anchor-id" href="{{ url('rpr/') }}">send</a>
$('#your-anchor-id').attr('href', $('#your-anchor-id').attr('href')   response.id)

On a side note, you shouldn't put a <button> inside an <a>.

  • Related