Archive for the ‘AJAX’ Category

jQuery Ajax call and result XML parsing

2 November, 2006

I have found jQuery to be one of the most powerful JavaScript libraries out there at the minute. I’ve been working with the base library and a number of plug-ins over the past couple of weeks and have found both the effects and AJAX methods to be both powerful and easy.

Here’s some code that I have used to look up an address. The data is served by an .aspx (.NET) page and I have included an example of the returned XML below.

jQuery code:

//Perform Ajax call – notice the number and postcode – these end up as querystring params and are taken in by AddressFinder.aspx
//’xml’ is an XML document object holding the returned XML
jQ.ajax({ type: “POST”, url: “AddressFinder.aspx”, data: “number=1&postcode=wn58ln”, dataType: “xml”, success: function(xml){

//This simple XPath XML function looks through the returned XML data
//All tags can now be accessed within the loop
var _number = “”;
var _line1 = “”;
var _town = “”;
var _city = “”;
var _country = “”;

//This function will loop for each match on addresses/address
jQ(“/addresses/address”, xml).each(function(){

_number = jQ(“number”, this).text();
_line1 = jQ(“line1″, this).text();
_town = jQ(“town”, this).text();
_city = jQ(“city”, this).text();
_country = jQ(“country”, this).text();

jQ(“#text11″).val(_line1);
jQ(“#text12″).val(_town);
jQ(“#text13″).val(_city);
jQ(“#text14″).val(_country);
});

XML returned from AddressFinder.aspx:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<addresses>
<address>
<number>6</number>
<line1>Almsberry Cresent</line1>
<town>Ashton – in – Makerfield</town>
<city>Wigan</city>
<country>England</country>
</address>
</addresses>

Did you find this demonstration helpful? If so leave me a comment and let me know if there are any other AJAX exmaples you’d like to see here. Thanks.

Atlas Errors

25 September, 2006

Error Message:

Assertion Failed: Could not resolve reference to object named “_PageRequestManager” for “dataContext” property on object of type “Sys.Binding”

Next error message:

Assertion Failed: No data context available for binding with ID “” and dataPath “inPostBack” on object of type “Sys.UI.Control”

This is a bug with atlas.

Make sure your script manager has the EnablePartialRendering set to true.