Ajax Processing a HTTP Response
Processing the HTTP Response: XML
<data >
<item0 >< address >1 Rose Lane , Lvpl </ address ></ item0 >
<item1 >< address > Lennox , 2 Rose Lane , Lvpl </ address ></ item1 >
<item2 >< address > Flat A , 3 Rose Lane , Lvpl </ address ></ item2 >
</data >
functi o n processXM L R e sponse ( xml ) {
var o = documen t . createElement ( ' option ' )
o. label = ' Selec t an addre ss '
o. value = ' '
sel = d o cument . g e t E l ementById ( ' adr ' )
sel . appendChild ( o )
adrs = xml . ge tElementsB y T a gName ( ' ad dress ' )
for ( i = 0; i < adrs . length ; i ++) {
o = d ocument . c r e a t e E l e m e n t ( ' opt ion ' )
o. label = o. text = adr [ i]. childNodes [0]. no d e Value
sel . appendChild ( o )
} }
< option value = '' > Select an address </ option >
< option value = ' 1 Rose Lane ' >1 Rose Lane , Lvpl </ option >
< option value = ' Lennox , 2 Rose Lane ' > Lennox , 2 Rose Lane , Lvpl </ option >
< option value = ' Flat A , 3 Rose Lane ' > Flat A , 3 Rose Lane , Lvpl </ option >
COMP519 Web Programming Lecture 26 Slide L26 – 22