PHP for Microsoft AJAX Library [转载]

2007-03-23 14:32:47 / 个人分类:PHP

    Ajax 技术着实火了一把。也有人乐在其中。在众多的 Ajax Library中再添一新丁。百花齐放才是春嘛!

    参考网站 http://codeplex.com/phpmsajax

  

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 scrīpts, 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 scrīpt 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>
<scrīpt type="text/javascrīpt" src="../../MicrosoftAjaxLibrary/MicrosoftAjax.js"></scrīpt>
<scrīpt type="text/javascrīpt" src="HelloService.php/js"></scrīpt>
</head>
<body>
Name: <input id="name" type="text" /> <input type="button" value="Say Hello" ōnclick="button_click(); return false;" />
<br />
Response from server: <span id="response"></span>
</body>
<scrīpt type="text/javascrīpt">
    function button_click() {
        HelloService.SayHello($get('name').value, function (result) { $get('response').innerHTML = result; });
    }
</scrīpt>
</html>
Last edited Jan 30 at 1:46 AM by SteveMarx, version 11
  


TAG: PHP

Open Toolbar