1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
function addLocation()
{
if(xhr == null) //If httpRequest not yet initialized, we create it
createHttpRequest();
openXMLFile(); //To open the xml file
var div = document.getElementById("infos");
var country = document.getElementById("country");
var continent = document.getElementById("continent");
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)
{
doc = xhr.responseXML.documentElement; //To assign the document to a var
var indexContinent = continentExists(continent);
if(indexContinent == -1) //if the continent does not exist
{
addContinent(continent);
}
addCountry(country, indexContinent);
updateInfos(); //Update infos to display the new country
}
else
{
alert("Server error!"); //Error from the server
}
}
};
}
function addContinent(continent)
{
alert("add continent"); //s'affiche
var newContinent = doc.createElement(continent); //Ne fonctionne pas
alert("continent created"); //ne s'affiche pas
doc.appendChild(newContinent);
alert("continent added");
} |
Partager