I am trying to pass associative ophp array to javascript function but it is giving me this error
Uncaught SyntaxError: Unexpected end of input
Here is my php code
foreach ($staff->roles as $role) {
$actionRoles .= $role->name . ',';
array_push($selected_roles,['id'=>$role->id,'name'=>$role->name]);
}
$tableAction = '
<div class="menu-item px-3">
<a onclick="editStaff(this,"'.json_encode($selected_roles).'")" >
Edit
</a>
</div>
';
you can see I am passing array to js function but when I click on it give me error
How I can pass this array from here and how I can receive array from js function ?
Try with this,
foreach ($staff->roles as $role) {
$actionRoles .= $role->name . ',';
array_push($selected_roles,['id'=>$role->id,'name'=>$role->name]);}$tableAction = '<div class="menu-item px-3">
<a onclick="editStaff(this,'.json_encode($selected_roles).')">
Edit
</a></div>';