在PHP中使用ASP.NET AJAX
發表于:2007-09-07來源:作者:點擊數:
標簽:
編寫Service文件 新建一個 php 文件,命名為EmployeeService.php。首先寫上這一句,include必要的支持代碼: require_once 'MSAjaxService.php'; 然后定義一個Employee類。四個屬性一目了然,不用多說: class Employee { public $Id; public $Name; public
編寫Service文件
新建一個
php文件,命名為EmployeeService.php。首先寫上這一句,include必要的支持代碼:
require_once 'MSAjaxService.php';
然后定義一個Employee類。四個屬性一目了然,不用多說:
class Employee
{
public $Id;
public $Name;
public $Email;
public $Salary;
function __construct($id, $name, $email, $salary)
{
$this->Id = $id;
$this->Name = $name;
$this->Email = $email;
$this->Salary= $salary;
}
}
接下來是EmployeeService類,繼承與MSAjaxService.php中的MSAjaxService基類。其中定義一個方法,用來返回一個Employee對象:
class EmployeeService extends MSAjaxService
{
function GetEmployee()
{
return new Employee(12345, "Dflying Chen", "Dflying@some.com", 1000);
}
}
然后新建一個EmployeeService的實例,并且調用基類的ProcessRequest()方法,處理該請求:
$theService = new EmployeeService();
$theService->ProcessRequest();
大功告成!
原文轉自:http://www.anti-gravitydesign.com