To begin examining the basic technique for reading an XML file. To do this we use a very simple document and assume that is the page that hosts the data, both the XML file are on the same domain. Here is the XML document to be imported:
Code:
<? Xml version = "1.0" encoding = "UTF-8"?>
<guide>
<guide>
Help <title> jQuery </ title>
<link> http://javascript.html.it/guide/more/168/guide-jquery/ </ link>
</ Help>
<guide>
<title> Guide Send Framework </ title>
<link> hhttp: //php.html.it/guide/more/195/guide-send-framework / </ link>
</ Help>
</ Guides>
Here is the code needed imports, let's take a look:
Code:
$ (Document). Ready (function () {
$. Ajax ({type: "GET", url: "guide.xml", dataType: "xml"
success: function (xml) {
$ (Xml). Find ('help'.) Each (function () {
var title = $ (this). find ('title'). text ();
var link = $ (this). find ('link'). text ();
link_markup var = '<a <li> href="'+link+'" title="'+title+'-HTML.it">' + title + '</ a> </ li>';
$ (Link_markup). AppendTo ('# guides');
});
}
error: function (request, error, type_error) {alert (error + ':' + type_error);}
});
});
To complete the picture in the markup necessary to insert a bulleted list with id="guide" and this is very simple:
Code:
<ul #id="guide"> </ ul>
At this point we begin to examine the key elements of the script: when invoked, as the request is made, how to manage the data.
Bookmarks