One more step is missing—what happens on the client once the response for the out-of-band
call is received? The following snippet shows a piece of client code that, when attached to a
button, fires the out-of-band call and refreshes the user interface:
function MoreInfo()
{
var empID = document.getElementById("EmployeeList").value;
var xml = SendRequest("default.aspx", empID);
// Update the UI
var label = document.getElementById("Msg");
label.innerHTML = xml.responseText;
}
According to the code, whenever the user clicks the button a request is sent at the following URL.
Note that 1 in the sample URL indicates the ID of the requested employee. (See Figure 1-5.)
default.aspx?outofband=true¶m=1
Figure 1-5 A manually coded out-of-band request in ASP.NET 1.x and ASP.NET 2.0
Displaying results correctly on most browsers can be tricky. Internet Explorer, in fact, supports
a number of nonstandard shortcuts in the DOM that just don’t work with other browsers. The
most common snag is retrieving references to HTML elements using the document.getElement-
ById method instead of the direct name of the element. For example, the following code works
on Internet Explorer but not on Firefox and other Mozilla-equipped browsers:
// Msg is the ID of a tag.
// This code works only with Internet Explorer
Msg.innerHTML = xml.requestText;
In summary, cross-browser JavaScript code is required to update the currently displayed page
on the client. At the same time, a number of assumptions must be made on the server to come
up with a working and effective environment. For this reason, frameworks are the only reasonable
way of implementing AJAX functionalities. Different frameworks, though, might provide a
different programming interface on top of an engine that uses the same common set of parts.
Category :
- ASP.NET AJAX in Person (1)
- Conclusion (1)
- The AJAX Core Engine (1)
- The AJAX Revolution (1)