在php中使用asp.net 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", "[email protected]", 1000);
}
}
然后新建一個employeeservice的實例,并且調用基類的processrequest()方法,處理該請求:
$theservice = new employeeservice();
$theservice->processrequest();
新聞熱點
疑難解答