HTML_AJAX
[ class tree: HTML_AJAX ] [ index: HTML_AJAX ] [ all elements ]

Source for file php_callback.php

Documentation is available at php_callback.php

  1. <?php
  2.  
  3. require_once 'HTML/AJAX/Server.php';
  4.  
  5. class Foo {
  6.     function bar()
  7.     {
  8.         return 'hello';
  9.     }
  10. }
  11.  
  12. function foobar()
  13. {
  14.     return 'hello';
  15. }
  16.  
  17. // start server
  18. $server = new HTML_AJAX_Server();
  19.  
  20. // register normal function
  21. $callback 'foobar';
  22. $server->registerPhpCallback($callback);
  23.  
  24. // register static method
  25. $callback = array('Foo''bar');
  26. $server->registerPhpCallback($callback);
  27.  
  28. // register object method
  29. $foo = new Foo;
  30. $callback = array($foo'bar');
  31. $server->registerPhpCallback($callback);
  32.     
  33. // handle the request
  34. if ($server->handleRequest()) {
  35.     exit;
  36. }
  37.  
  38. ?>
  39. <html>
  40.     <head>
  41.         <script type='text/javascript' src="?client=all&amp;stub=all"></script>
  42.         <script type="text/javascript" language="Javascript">
  43.         <!--
  44.         
  45.         HTML_AJAX.defaultServerUrl = 'php_callback.php';
  46.         
  47.         function testCallPhpCallback(cb)
  48.         {
  49.             HTML_AJAX.callPhpCallback(cb, showResult);
  50.         }
  51.         
  52.         function showResult(result)
  53.         {
  54.             alert(result);
  55.         }
  56.         
  57.         var foo = new foo;
  58.         
  59.         //-->
  60.         </script>
  61.     </head>
  62.     <body>
  63.         using HTML_AJAX.callPhpCallback()
  64.         <ul>
  65.             <li><a href="javascript:testCallPhpCallback('foobar')">normal function</a></li>
  66.             <li><a href="javascript:testCallPhpCallback(['Foo', 'bar'])">static method</a></li>
  67.             <li><a href="javascript:testCallPhpCallback([foo, 'bar'])">object method</a></li>
  68.         </ul>
  69.         exported
  70.         <ul>
  71.             <li><a href="javascript:alert(foo.bar())">object method</a></li>
  72.         </ul>
  73.     </body>
  74. </html>

Documentation generated on Mon, 11 Mar 2019 15:59:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.