CodePlex open source project on the help of PHP for Microsoft AJAX Library help, we can use PHP in the ASP.NET AJAX a lot of the core functions.
Download the installation
PHP for Microsoft AJAX Library is currently only in Alpha stage, would seem to be actually used early for that, the only fresh.
Pre-demand version of PHP 5.2 and must be installed php-json module.
Download Address: http://www.codeplex.com/phpmsajax/Release/ProjectReleases.aspx?ReleaseId=1692
Installation method:
Download PHP for Microsoft AJAX Library and extract
Download Microsoft AJAX Library (http://ajax.asp.net)
PHP Web Service in the code include some MSAjaxService.php.
Web Service calls in the middle of the page, the introduction of MicrosoftAjax.js document.
The following point of view of a "classic" scene: call server-side methods to obtain the type of complex.
Service to prepare documents
Create a new php file, named EmployeeService.php. This is the first to write a, include the necessary support for the code:
require_once 'MSAjaxService.php';
Then the definition of an Employee category. The four properties at a glance, Needless to say:
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 is the next category, inheritance and MSAjaxService.php of MSAjaxService base class. One definition of a method for a return to the Employee object:
class EmployeeService extends MSAjaxService
(
function GetEmployee ()
(
return new Employee (12345, "Dflying Chen", "Dflying@some.com", 1000);
)
)
Then a new EmployeeService example, and call the base class ProcessRequest () method to deal with the request:
$ theService = new EmployeeService ();
$ theService-> ProcessRequest ();
Done!
Calling the preparation of the page
Create a new page, php or html can be - a relatively simple procedure. This time we did not help the ScriptManager, the introduction of ASP.NET AJAX client-side script file of the Service as well as the above can only rely on the hand. Attention EmployeeService.php / js that can be Clients of the Service agents, and the ASP.NET platform, like the syntax:
<head>
<title> ASP.NET AJAX On PHP Demotitle>
<script type="text/javascript" src="MicrosoftAjaxLibrary/MicrosoftAjax.js"> script>
"text / javascript" src = "EmployeeService.php / js"> script>
head>
UI part of the process is very simple button to trigger asynchronous call,
The results show that used to call:
<body>
<input id = "btnGetEmployee" type = "button"
value = "Get an Employee" onclick = "return btnGetEmployee_onclick ()" />
<div id="resultDiv">
div>
body>
In the button's click event handler, call the Service, grammar and also in ASP.NET AJAX, very convenient:
function btnGetEmployee_onclick ()
(
EmployeeService.GetEmployee (onSucceeded);
)
In the callback function, the Employee object to be displayed to the resultDiv:
function onSucceeded (result)
(
var sb = new Sys.StringBuilder ( "Server returns an Employee object:");
sb.append ( "Id:" + result.Id + "");
sb.append ( "Name:" + result.Name + "");
sb.append ( "Email:" + result.Email + "");
sb.append ( "Salary:" + result.Salary + "");
$ get ( "resultDiv"). innerHTML = sb.toString ();
)
Done! |