ajax
编写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();
大功告成!