Search Wiki:
A small set of PHP files to support using the Microsoft AJAX Library with PHP web applications. The current release supports creating web service proxies in PHP code such that the Microsoft AJAX Library (a free download from http://ajax.asp.net) can call them from client-side code. Future releases will support localization and globalization, debug and release scripts, and more features inspired by ASP.NET AJAX.

Download


Download the current release: 3 Alpha

Requirements


  • A web server -- Steve has personally tested on IIS7 (Vista) and Apache (Ubuntu 6.06, with PHP5.2 from 'feisty')
  • PHP 5.2 -- 5.2 is required for json_encode/json_decode; on older versions you can manually install php-json

Installation


  1. Download the current release and unpack it locally.
  2. Download the Microsoft AJAX Library from http://ajax.asp.net.
  3. From your PHP code, include MSAjaxService.php from your service code.
  4. From your client code, include MicrosoftAjax.js via a script tag. (This file is part of the Microsoft AJAX Library you downloaded in step 2.)

NOTE: The samples included in the full distribution will not work until you download the Microsoft AJAX Library. See the readme.txt in the MicrosoftAjaxLibrary directory where you unpacked PHP for Microsoft AJAX Library.

Hello World Example


A basic example showing how to expose a web service from PHP and consume it from the browser. This sample can be found under samples/HelloWorld in the source distribution.

HelloService.php:

<?php
 
require_once '../../dist/MSAjaxService.php';
 
class HelloService extends MSAjaxService
{
    function SayHello($name)
    {
        return "Hello, " . $name . "!";
    }
}
 
$h = new HelloService();
$h->ProcessRequest();
 
?>

index.html:

<html>
<head>
<title>Hello, World!</title>
<script type="text/javascript" src="../../MicrosoftAjaxLibrary/MicrosoftAjax.js"></script>
<script type="text/javascript" src="HelloService.php/js"></script>
</head>
<body>
Name: <input id="name" type="text" /> <input type="button" value="Say Hello" onclick="button_click(); return false;" />
<br />
Response from server: <span id="response"></span>
</body>
<script type="text/javascript">
    function button_click() {
        HelloService.SayHello($get('name').value, function (result) { $get('response').innerHTML = result; });
    }
</script>
</html>
Last edited Jan 29 2007 at 5:46 PM  by SteveMarx, version 11
Comments
ripi1000 wrote  Jan 24 2007 at 9:16 AM  
Hello, this is a really cool idea. I'll try this today.
Hopefully I'll hear more of this.
thx
ripi1000

SteveMarx wrote  Jan 24 2007 at 6:23 PM  
Thanks, ripi! Let me know what you think and don't be shy about using that Issue Tracker.

ripi1000 wrote  Jan 29 2007 at 10:11 AM  
So, as I've told you I've tried it. And what schould I say: IT WORKS LIKE A CHARM!! Really cool. It would be great if you could post a bit more examples. Perhaps how to handle complex objects?? Greetz ripi

ockham wrote  Mar 21 2007 at 12:29 AM  
Is it possible to use the ASP.NET AJAX Control Toolkit with PHP? If so, could someone please post sample php code for any of the controls? -- (PasswordStrength, FilteredTextBox, etc.) -- Some of us beginner noobs, such as myself, are obvious clueless! Thanks in advance.

dewmeht wrote  Jun 22 2007 at 6:40 PM  
Do you know what I will have to do to make your technique work with ASP.NET 1.1?

Updating...