View Full Version : PHP Function Call from JavaScript
SorentoUltimate
01-22-2010, 07:40 PM
Hello everyone,
I have a JavaScript at forumroot\clientscript\myjavascript.js
I have a PHP File at forumroot\includes\functions_myfunctions.php
Into functions_myfunctions.php there are one function named mytestfunction.
How i Call/Run mytestfunction from the JavaScript ?
If I understand you correctly you can't, at least not directly, because the php runs on the server before the page is sent to the browser, and the javascript runs in the browser after it's received. But there may be a way to do what you want to do, either write javascript into the output page to do it or else make a background ('AJAX') call to the server to do it.
SorentoUltimate
01-22-2010, 08:39 PM
either write javascript into the output page to do it or else make a background ('AJAX') call to the server to do it.
Thanks kh99,
can you explain little more who can i do that things ?
Can YOU HELP ME DO IT WITH AJAX???
Hmmm...well, it's documented out there so I won't try to repeat all the details (which I'd have to look up anyway). I think probably the best thing would be to find an example. One I ran across recently is the Cyb Chatbox mod (https://vborg.vbsupport.ru/showthread.php?t=201283&highlight=cyb+chatbox), it makes a background request to update the messages and uses a plugin on the misc_start hook. There's no magic on the server, it's just a normal http request. Sorry I'm not more help, but if you run in to problems you can post them here.
I just read your other thread - if you know the text you want to insert when the button is pressed, then it would probably be much easier to write it in to the page output as a javascript string and do something like Lynne suggested.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.