![]() |
| ||
| How to call a PHP function from Javascript and return the results back into Javascrip Hi, I have been working on trying to figure out, how I can get a web page to call a PHP function and have the results returned to the client for processing, for about two weeks. I hope I am in the right forum (ie. Javascript). I will also post in PHP and SOAP forums as well just to be sure. Here is the issue PS: I don't have code to post because I really don't know how to implement this. 1. UserA loads a webpage from ServerA. In it it has a javascript function which "on web page loading" calls a remote function on another web server, ServerB. This remote function is written in PHP and accesses a MySQL database, the results of the DB query is an array. 2. This array gets returned by the remote server to the javascript function that made the initial call. The array then gets processed by the javascript function. Now I know that Javascript is client side and PHP is server side. I also discovered that to make this happen I will need to use some sort of RPC functionality. Some sites/ideas that I have found on the net are............ 1. XML-RPC www.ashleyIT.com using JSRS 2. and possibly SOAP. I have spent the last few days trying to get ashleyIT's XML-RPC implementation to work but the documentation is scarce, the site and forum look like they aren't being used anymore, and I am starting to wonder if there is not a more popular/modern implementation that I should be considering. Question So now the question. Does anyone know what implementation of RPC I could use? I am researching SOAP but so far I have not found a SOAP implementation using Javascript calling PHP functions. Is there anything else that I might be able to use other than XML-RPC and SOAP? Thanks for your time. |
| ||
| Re: How to call a PHP function from Javascript and return the results back into Javas Next time? DON'T POST THE SAME THREAD IN MULTIPLE FORUMS Thanks! |
| ||
| Re: How to call a PHP function from Javascript and return the results back into Javas Maybe you could use an iframe? You can make the frame small so the user may not even know it is there. Load a form into it initially to call your php function and then read the results with the javascript once it reloads.... |
| ||
| Re: How to call a PHP function from Javascript and return the results back into Javas The best way would be to make an ajax call, but the proposed iframe solution would work as well. You don't even have to make the iframe small, just set it's style attribute to: style="visibility: hidden" |
| ||
| Re: How to call a PHP function from Javascript and return the results back into Javas I would use an ajax call to the following script. $allowedfuncs = array([allowed function calls]) //Or something along those lines. Don't see a need for an iframe. |
| ||
| Re: How to call a PHP function from Javascript and return the results back into Javas Please see the http://satoewarna.com/jqsajax/ it will help you in calling PHP function/method from javascript. Quote:
|
| ||
| Re: How to call a PHP function from Javascript and return the results back into Javas Quote:
I don't have experience in XML-RPC or SOAP but if I understand correctly, the HttpRequest object does not allow cross-site requests. I believe this is going to be included in future releases of some browsers though. Correct me if I'm wrong here. You can always make an Ajax call to a locally hosted PHP script and have it query the remotely served database. You can make an Ajax query to a locally hosted PHP script and have it make a call to a remotely hosted PHP script and set up a conversation that way. You can use an iframe as mentioned above Of course there are a multitude of Ajax libraries available these days -- not all created equal though in terms of robustness or ease of implementation. Or you could learn how to roll your own and gain invaluable experience that way. Another fun non-Ajax (read old-skool) trick is to use JavaScript to call the PHP file as a JavaScript include file -- see example bellow. page: test.html <html> page: remote.php <?php What ever way you do it should be a learning experience ... :-) |
| ||
| Re: How to call a PHP function from Javascript and return the results back into Javas Quote:
see it in action at: call php with javascript demo page this code is explained at call php with javascript |
| All times are GMT -4. The time now is 5:01 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC