Pankaj Pankaj - 1 year ago 37
Javascript Question

Issue while trying to append route parameter in js

Below is my js code that is appending the route and its parameter in anchor tag.

var href = "{!! route('ShowUserMainForm', ['RoleID'=>" + row.RoleID + "]) !!}";

var UserColumn = "<td><a href=' " + href + "'><button>Users</button></a></td>";


It gives below url

http://localhost:1234/public/system-users/%20+%20row.RoleID%20+%20

I am expecting below.


http://localhost:1234/public/system-users/1


Am I missing anything?

Answer Source

No. of ways to do it:

Because {!! !!} block codes render before JavaScript code so you need to create route and then concat RoleID outside {!! !!} .

if row.RoleID is json :

var href = "public/system-users/" + row.RoleID

or

var href = "{!! route('ShowUserMainForm') !!}" + row.RoleID;

or

var href = "{!! route('ShowUserMainForm', ['RoleID'=>'']) !!}" + row.RoleID;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download