Can you call php from javascript?

JavaScript is a client side language, PHP is a server side language. Therefore you can’t call PHP functions directly from JavaScript code. However, what you can do is post an AJAX request (it calls a PHP file behind the scenes) and use that to run your PHP code and return any data you require back to the JavaScript.
For More Information Please Refer:

You May Also Like to Read: