Auction Demo Architecture: HTTP Requests

All the HTTP requests for XML data go through the XML data source object (DSO), which is described in the XML DSO examples. The DSO provides a load method that takes a relative URL -- which, in this case, points to the ASP scripts.

The first step is to load all the XML items being auctioned, and start a 4-second timer for polling the server for updates.


function initialize()
{		
    // load initial XML into main dso
    xmldso.load("pdcxml.asp");
	
    // Start timer for polling for updates
    setInterval("UpdateXML();", 4000);
}

The UpdateXML function is automatically called every 4 seconds, and we then use a second XML DSO object to get the update using the UPDATE.ASP script, passing the current timestamp. If an update is actually received, the update is given to the main XML DSO to merge in with the rest of the data. UpdatePage is then called to rebuild the user interface to display the updated data.

Note: This example is simplified. What you'll find in the real demo source code is a little more complicated because it is all done asynchronously using script callbacks. This is required so that the HTTP requests do not hold up the user interface.


function UpdateXML()
{		
    // load update into xmldso 2
    xmldso2.load("update.asp?timestamp=" + getLastTimeStamp());
    var d = xmldso2.getDocument();
    if (d.root != null) 
    {
        // then merge update back into main dso
        xmldso.handleUpdate(d.root);
        UpdatePage();
    }
}

The makeBid function is used to send a new bid to the server, using the MAKEBID.ASP script, passing the bid information as URL query parameters. The result of the bid then tells us whether the bid actually succeeded. If not, we display the error message from the server, and if so, we ask the server for an update.


function makeBid()
{
    // Assemble the bid parameters
    var bidder = validate("bidder");
    var price = validate("price");
    var item = xmldso.getDocument().root.children.item("ITEM")
    var title = item.children.item("TITLE").text;
 
    // get results of makebid asp in xmldso 2.
    xmldso2.load("makebid.asp?title=" + title + 
        "&price=" + price.value +
        "&bidder=" + bidder);
    var d = xmldso2.getDocument();
    if (d != null && d.root != null) {
        if (d.root.tagName == "ERROR") {
            alert(d.text);  // display the error 
        } else {
            UpdateXML();  // get next update from server 
        }
    }
}

HomeBack to the XML Auction Demo overview.

© 1997 Microsoft Corporation. All rights reserved. Terms of use.