PHP for Microsoft Ajax Library

The Microsoft AJAX Library is a pure-JavaScript library that's used by ASP.NET AJAX but is also available as a separate download. Because it's pure JavaScript, it's not tied to ASP.NET on the backend. PHP for MS AJAX is code to help you make use of the Microsoft AJAX Library from PHP applications. With this first Alpha release, it simply supports exposing PHP classes as AJAX-enabled web services, just as in ASP.NET applications. In fact, the generated proxies are identical to what you get from ASP.NET, meaning you can have full interoperability.

Hello World

The service on the backend so to speak:


HTML:
  1. <?php
  2. require_once '../../dist/MSAjaxService.php';
  3. class HelloService extends MSAjaxService
  4. {
  5. function SayHello($name)
  6. {
  7. return "Hello, " . $name . "!";
  8. }
  9. }
  10. $h = new HelloService();
  11. $h->ProcessRequest();

And the front end that will talk to it:



  1. <title>Hello, World!</title>
  2. <script type="text/javascript" src="../../MicrosoftAjaxLibrary/MicrosoftAjax.js"></script>
  3. <script type="text/javascript" src="HelloService.php/js"></script>
  4. </head>
  5. Name: <input id="name" type="text" />
  6. <input type="button" value="Say Hello" onclick="button_click(); return false;" />
  7. <br />
  8. Response from server: <span id="response"></span>
  9. </body>
  10. <script type="text/javascript">
  11. function button_click() {
  12. HelloService.SayHello($get('name').value, function (result) {
  13. $get('response').innerHTML = result;
  14. });
  15. }
  16. </script>
  17. </html>

If you have better solution, just tell me !


0 comments: