How can I pass variables and data from PHP to JavaScript?

Ask a question

I have a variable in PHP, and I need to send its value to JavaScript. How can I do that?

My code is looks like this:

// Makes an API and database call
= $myService->getValue();

I have JavaScript code that needs val and looks along the lines of:

// I tried this, but it didn’t work

 // This didn’t work either
<?php myPlugin.start($val); ?>

// This works sometimes, but sometimes it fails
Coin iconoffer bounty
add comment

0 Answer

Your Answer