Steve Marx has created a
PHP library for the Microsoft Ajax 1.0 release that uses the JavaScript piece in PHP land.
The Microsoft AJAX Library is a pure-JavaScript library that's used by ASP.NET AJAX but is also available as a separate download. Because it's pure JavaScript, it's not tied to ASP.NET on the backend. PHP for MS AJAX is code to help you make use of the Microsoft AJAX Library from PHP applications. With this first Alpha release, it simply supports exposing PHP classes as AJAX-enabled web services, just as in ASP.NET applications. In fact, the generated proxies are identical to what you get from ASP.NET, meaning you can have full interoperability.
Hello World
The service on the backend so to speak:
HTML:
-
-
<?php
-
-
require_once '../../dist/MSAjaxService.php';
-
-
class HelloService extends MSAjaxService
-
{
-
function SayHello($name)
-
{
-
return "Hello, " . $name . "!";
-
}
-
}
-
-
$h = new HelloService();
-
$h->ProcessRequest();
-
And the front end that will talk to it:
HTML:
-
-
-
-
-
<script type="text/javascript" src="../../MicrosoftAjaxLibrary/MicrosoftAjax.js"></script>
-
<script type="text/javascript" src="HelloService.php/js"></script>
-
</head>
-
-
Name:
<input id="name" type="text" />
-
<input type="button" value="Say Hello" onclick="button_click(); return false;" />
-
-
Response from server:
<span id="response"></span>
-
</body>
-
-
function button_click() {
-
HelloService.SayHello($get('name').value, function (result) {
-
$get('response').innerHTML = result;
-
});
-
}
-
</script>
-
</html>
Microsoft has announced the
final 1.0 release of ASP.NET Ajax (a.k.a. Atlas).
It consists of a core platform, and a bunch of controls:
ASP.NET AJAX 1.0
ASP.NET AJAX 1.0 delivers a rich client-side AJAX library that provides cross platform, cross browser support for a core JavaScript type-system, JSON-based network serialization stack, JavaScript component/control model, as well as common client JavaScript helper classes. ASP.NET AJAX also delivers a rich server-side library that integrates AJAX functionality within ASP.NET, and enables developers to easily AJAX-enable existing ASP.NET 2.0 sites with minimal effort.
ASP.NET AJAX is available for free, and can be used with ASP.NET 2.0 and VS 2005. It is a fully supported Microsoft product, and is backed by a standard 10 year Microsoft support license (with Microsoft Product Support available via phone 24 hours a day x 7 days a week).
ASP.NET AJAX Control Toolkit
In addition to the fully-supported ASP.NET AJAX 1.0 release, you can use the more than 30 free ASP.NET AJAX enabled controls available within the ASP.NET AJAX Control Toolkit. The control toolkit is a shared-source collaborative project built together by a team containing both Microsoft and non-Microsoft developers (visit the CodePlex Project to learn more, or volunteer to contribute). All source for the controls is provided completely for free (with full re-use and modification rights).
The majority of controls within the ASP.NET AJAX Control Toolkit leverage the "Control Extender" pattern that the core ASP.NET AJAX library introduces, and which delivers a super powerful way to easily enable specific AJAX scenarios on a site with minimal effort.
Future Plans
While the core ASP.NET AJAX 1.0 release is now officially shipped, we are definitely not slowing down. :-)
All of the ASP.NET AJAX 1.0 features will be integrated directly into the next release of ASP.NET (codename: "Orcas"). Visual Studio "Orcas" will also provide client-side JavaScript intellisense, JavaScript compilation checking, and rich JavaScript debugging support for ASP.NET AJAX scenarios.
We are also already at work on the next ASP.NET AJAX release, and will continue to add new features and improvements to the supported ASP.NET AJAX core. You can already start using many of these new features with the ASP.NET AJAX Futures CTP (available for download now on the ASP.NET AJAX site - it also supports a "go live" license).
Is the Microsoft camp of developers going to listen to the ivory tower and use this? Or will you be looking for alternatives?
Evil Microsoft. The client-side DOM event model in Atlas (ASP.NET Ajax Extensions) was the IE model. Atlas implemented this model for the other browsers to make it work, and
many didn't like this.
This has now
all changed and a new API is in town.
The new model for DOM events is thus introducing a new API, but at least it's closely modeled after the standard APIs so it should feel pretty familiar. There are many differences in the implementations of DOM events that we needed to abstract. The first one is in the names of the methods that you call to add an event. In standard browsers, you use add/removeEventListener, in IE it's attach/detachEvent. The event names themselves are different: "click" is "onclick" in IE. Then, you have to abstract the signature of the event handlers themselves: in IE the parameters come from the global window.event object, in other browsers they are passed as a parameter. Finally, the contents of the event parameter object are themselves widely divergent from one browser to the other: mouse buttons don't have the same values for example, and some very useful stuff like mouse positions is missing altogether from the standard.
To do work you now:
// register a handler (shortcut for Sys.UI.DomEvent.addHandler)
$addHandler(myDomElement, "click", someFunction);// Enums in event handlers
function myClickHandler(e) {
if (e.button === Sys.UI.MouseButton.leftButton) {
//...
}
}
function myKeyUpHandler(e) {
if (e.keyCode === Sys.UI.Key.enter) {
//...
}
}
There are also some other new features such as helpers to make component developers lives easier.
For example, an accessible hover behavior might want to subscribe to mouseover, mouseout, focus and blur. To do that, you'd typically create delegates to your handlers and then wire up these delegates to the DOM events one by one. From your "dispose" method, you'd also have to remove those handlers one by one and get rid of the delegates. Seeing that this pattern was repeated over and over again in almost any control or behavior sample, we decided to add helpers to batch those operations. So here's how you would wire up all those events:
$addHandlers(this.get_element(), {
mouseover: this._onHover,
mouseout: this._onUnhover,
focus: this._onHover,
blur: this._onUnhover
}, this);

Microsoft recently released a major upgrade to Live Search on Live. com. Here’s an overview of the Ajax-powered image search. The service is pretty snappy, a great leap in usability over “Image Search 1.0″. It’s exciting to see some bleeding-edge patterns used in a service like this.
Features include:
- “Smart Scroll”. This is the Virtual Workspace pattern applied to a long list/table, or what Bill Scott calls “Death To Paging”. There’s no “Next/Previous 20 results” - you simply browse all the results by scrolling, and the page loads new images as you scroll, as well as updating the result count. There have been some nice demos along these lines, but this is the first major site to drop pagination in this way (any other examples?)
- Bookmarkable URLs. Excellent! A major site finally adjusts the URL to reflect Javascript state, so you can bookmark it and send it to your friends. The technique involves setting the # property in the URL (the “fragment identifer”), so you get a bookmarkable URL like http://search.msn.com/images/results.aspx#imagesize=all&q=pac-man.
But we all know Ajax breaks REST/bookmarks/history ;).
- Scratchpad. An optional scratchpad lets you build a collection of images together for later use. You can drag images into the scratchpad, drag to rearrange them, and drag them between different collections.
- Embedded web page. Using an embedded IFrame, the original web page containing the image is shown inside the results area.
- Adjustable image size. Pull a Slider back and forth to quickly zoom the images in and out.
Happily conspicuous by its absence is the
Live Search. pattern. The interface requires you to explicitly click the search button rather than continuously updating, which would have been inappropriate for this app.
All in all, a great effort and a chance to see some experimental Ajax features running on a high-profile site.
Peter Gurevich and Justin Rogers from Microsoft’s IE team recently wrote a blog entitled “
IE + JavaScript Performance Recommendations - Part 1“. It’s an interesting read, containing such tips as:
- Precede your variables with var if you are truly defining them in the current scope
- Cache Variables Whenever Possible
- Cache Function Pointers at all costs
- Cache Function Pointers at all costs