0

I want to call a php function that doing something inside of javascript function

for example:

function runPhp(){
     <?php echo "I'm PHP inside of Javascript function"  ?>
}
ALIK3DAV
  • 21
  • 5
  • 3
    Make sure you understand [the concept](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) you're working with. – Teemu May 27 '22 at 06:35
  • 1
    I wrote a lengthy explanation how PHP and Javascript interact here: https://stackoverflow.com/questions/72022099/how-to-make-the-value-stored-in-the-php-session-update-with-the-ajax-submission/72023066#72023066 – bloodyKnuckles May 27 '22 at 07:34
  • 1
    You can use Javascript [Fetch](https://javascript.info/fetch) or [XHR](https://javascript.info/xmlhttprequest) technology to retrieve data from the server without reloading the page in the browser. – bloodyKnuckles May 27 '22 at 07:39
  • @bloodyKnuckles this is really helpful! i think this can help me to solve my problem thank you – ALIK3DAV May 27 '22 at 09:38
  • 1
    Another thought came to mind. If the data can be provided upon initial loading of the page you can do something like this: `function runPhp(){ alert(''); }`. But if you need fresh data then Fetch or XHR does the job. – bloodyKnuckles May 27 '22 at 13:59

0 Answers0