I've an application, developed using Yii2 framework. In my application, I've a view.php that has an element and a button. The element <div id="userId">
contain the id
of login user, and I want to use the button to get data from column that called header_name
from header_table
in my SQL based on the id
that has got from the element.
This is the code
View.php
<?php
//some code
?>
<div id="userId" style="display: none"> <?php echo $userId; ?> </div>
<p>
<button type="button" onclick="getHeader()"class="headerBtn">Use Saved Header</button>
<p>
and
upload_header.js
function getHeader(){
var id = document.getElementById('userId').textContent;
}
I've successfully get the $userid
from view.php in my upload_header.js. But I dont't know how to get the data from sql.
How do I can get data from SQL through javascript?
Thanks, any help will be appreciated :)
Note:
I've read How to get data from database in javascript based on the value passed to the function and try the suggestion, but it didn't solve my case. Thanks