VJ’s Warez

PHP for Microsoft Ajax Library

Posted on: January 3, 2009

Steve Marx has created a PHP library for the Microsoft Ajax 1.0 release that uses the JavaScript piece in PHP land.

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:

  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>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

VJ’s Warez

%d bloggers like this: