Enhancing PHP Via the ASP.NET AJAX Framework: A Second Look - Post Code Examination
(Page 3 of 4 )
Due to the above examination, we cannot utilize the client-side offline DataSource component (in the xml-script declarative mode) and invoke the web service in the JavaScript mode.
A placeholder and the related templates for ASP.NET AJAX client-side control ListView are defined within the first part of the <body> text. As for how the templates correspond to the xml-script code snippet below, you can refer to the associated online ASP.NET AJAX tutorials at http://asp.net/ajax/. Here, we continue to leave space for web service invocation discussion.
When you click 'Get Animals,' the associated click event handler GetAnimals() is triggered. Then the control stays inside the JavaScript and the web service method is invoked. The code is listed below:
function GetAnimals()
{
AnimalService.GetAllAnimals(OnCompleted);
}
function OnCompleted(items)
{
$find("Results").set_data(items);
}
It all seems to call a local method, doesn't it? This is due to the automatically-generated client-side web service proxy discussed above. We first find the ListView instance 'Results' (not the 'div' DOM element!), and by calling the method set_data() of the ListView control, we successfully assign data to the control. All this occurs within the callback function OnCompleted() via the ASP.NET AJAX client-side global method 'findComponent' ('$find' for short).
By the way, we can use the debug techniques introduced in the Microsoft AJAX Library to track down the interesting data posted from the server side. To do this, we just, as usual, put a <textarea> element with the ID attribute 'TraceConsole' in the proper location of the page and then use methods of the Sys.Debug class to debug the related data. Figure 5 corresponds to the tracking snapshot the uses the Sys.Debug.traceDump() method.
Figure 5-use Microsoft AJAX Library's debug support to debug the sample
_html_m7da8cad7.png)
Last but not least, in the above xml-script declarative programming, readers should have been aware that by introducing PreviewScript.debug.js, not only can we utilize the xml-script mode to facilitate the client-side programming, but also to use many new concepts, such as transformer components, validate components, actions, behaviors, etc. so as to strengthen and extend the client ability.
Now, it's time to take a look at the running-time snapshot of our sample.
Next: Watch the result of asynchronously invoking the PHP web service >>
More ASP.NET Articles
More By Xianzhong Zhu