0

I want to pas this data to a javascript function that is in a javascript file :

    $data = $this->model_member->fetchMemberData();

The javascript function takes as a parameter the id_member that's inside the $data variable.It is called on button click from a view, but if I pass the data to the view I'll have to load it and I don't want that since it is already loaded. How can I pass this data directly to the js function?

annie
  • 177
  • 2
  • 3
  • 15
  • Possible duplicate of [How to pass variables and data from PHP to JavaScript?](https://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript) – Daniel Aug 31 '17 at 09:05

1 Answers1

0

There are many ways -

1 - You can use php tags in your js code. So you can access the variable like this -

var id_member = "<?php echo $data['id_member'] ?>";

2 - Store that $data in one hidden variable and than access it using any selector. For ex -

<input type="hidden" class="id_member_hidden">

var id = $(".id_member_hidden:hidden").val();

Hope this will help you to solve your problem.

Nikhil G
  • 2,096
  • 14
  • 18