<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PredictiveFetchDemo.aspx.cs" Inherits="AJAX.PredictiveFetchDemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>AJAX Design Pattern: Predictive Fetch - WebService</title>
<script lang="javascript" type="text/javascript">
var stats; // global variable used to store the fetched data before
it's needed
function pageLoad() {
if (document.getElementById('ddlPlayers').value != "blank_player") {
//
Use the JavaScript proxy object to make an asynchronous call to an ASP.NET Web
Service
//
Proxy Web Method call requires Web Method parameters, callback function,
timeout function, and error function.
AJAX.MLBService.GetPlayerStats(document.getElementById('ddlPlayers').value,
onComplete, onTimeout, onError);
}
}
function GetInfo() {
document.getElementById("content_area").innerHTML = stats;
}
//
callback function used to perform some action when an asynchronous request is
completed
function onComplete(data) {
// store
the fetched data in the global variable until it's needed
stats =
data;
}
//
function is called when an error occurs during an asynchronous request
function onError(data) {
alert("Error Occured");
}
//
function is called when a request takes a long period of time during an
asynchronous request
function onTimeout(data) {
alert("A Timeout Occured");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/MLBService.asmx" />
</Services>
</asp:ScriptManager>
<asp:Image ID="imgPlayer" runat="server" Height="250px"
ImageUrl="~/images/blank_player.jpg"
style="top: 30px; left: 25px; position: absolute" Width="200px" />
<asp:DropDownList ID="ddlPlayers" runat="server"
style="top: 320px; left: 25px; position: absolute; height: 20px; width: 201px; bottom: 404px;"
AutoPostBack="True" OnSelectedIndexChanged="ddlPlayers_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="blank_player">Select Player</asp:ListItem>
<asp:ListItem Value="roy_halladay">Roy Halladay</asp:ListItem>
<asp:ListItem Value="cole_hamels">Cole Hamels</asp:ListItem>
<asp:ListItem Value="ryan_howard">Ryan Howard</asp:ListItem>
<asp:ListItem Value="cliff_lee">Cliff Lee</asp:ListItem>
<asp:ListItem Value="roy_oswalt">Roy Oswalt</asp:ListItem>
<asp:ListItem Value="hunter_pence">Hunter Pence</asp:ListItem>
<asp:ListItem Value="jimmy_rollins">Jimmy Rollins</asp:ListItem>
<asp:ListItem Value="chase_utley">Chase Utley</asp:ListItem>
<asp:ListItem Value="shane_victorino">Shane Victorino</asp:ListItem>
</asp:DropDownList>
<input id="btnGetInfo" type="button" value="Get Information" onclick="GetInfo();"
style="top: 320px; left: 243px; position: absolute; width: 135px; height: 28px;" />
<br />
<div id="content_area"
style="top: 350px; left: 26px; position: absolute; width: 135px; height: 28px;">
</div>
</form>
</body>
</html>