A
A
Alexander2015-10-07 12:49:34
PHP
Alexander, 2015-10-07 12:49:34

How to call a php function from JavaScript?

there is a function in php

function md (){
return "Text";
}

How can I call it when the element is clicked?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Novikov, 2015-10-07
@kentuck1213

Ajax request

I
Ivanq, 2015-10-07
@Ivanq

No way. JavaScript is called on the client, PHP on the server. I once had a similar question too.
However, it is possible to call js from php -

<?php
echo "<script>my_js_func()</script>";
?>

True, you can use AJAX or something like that if you need to get some data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question