Enhancing PHP Via the ASP.NET AJAX Framework: A Second Look
(Page 1 of 4 )
Welcome to the second and final article in this tutorial about introducing the ASP.NET AJAX client-side framework into PHP programming. The first article covered how to set up the web service and this article will complete the discussion so we can fully utilize the AJAX feature within PHP via the Microsoft AJAX Library.
Write an HTML page to invoke the PHP web service
Now that the web service is ready to use, we can write a common web page (it can be a .php, .htm, or .html file-here we select the .html form) to invoke the web service. The sample .html file we built here is named index.html. And for convenience, we listed all the related source code below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ASP.NET AJAX On PHP Demo</title>
<link href="site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="MicrosoftAjax.js"></script>
<script type="text/javascript" src="PreviewScript.debug.js"></script>
<script type="text/javascript" src="AnimalService.php/js"></script>
</head>
<body>
<div id="Contents">
<div>
<input type="button" onclick="GetAnimals()" value="Get Animals" />
</div>
<!-- Visual templates for ListView control-->
<div id="Results">
<div style="display:none;">
<div id="Results_layout">
<div id="Results_layout_parent">
<div id="Result_item" class="resultItem">
<span id="Result_Name" class="Result_Name"></span>
<span id="Result_Category" class="Result_Category"> </span>
<span id="Result_Color" class="Result_Color"></span>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function GetAnimals()
{
AnimalService.GetAllAnimals(OnCompleted);
}
function OnCompleted(items)
{
$find("Results").set_data(items);
}
</script>
<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<components>
<listView id="Results"
itemTemplateParentElementId="Results_layout_parent">
<layoutTemplate>
<template layoutElement="Results_layout" />
</layoutTemplate>
<itemTemplate>
<template layoutElement="Result_item">
<label id="Result_Name">
<bindings>
<binding dataPath="Name" property="text" />
</bindings>
</label>
<label id="Result_Category" >
<bindings>
<binding dataPath="Category" property="text" />
</bindings>
</label>
<label id="Result_Color" >
<bindings>
<binding dataPath="Color" property="text" />
</bindings>
</label>
</template>
</itemTemplate>
</listView>
</components>
</page>
</script>
</body>
</html>
Next: Code Examination >>
More ASP.NET Articles
More By Xianzhong Zhu