This is an example of my xml file, with <studentenhuizen> repeated multiple times:
<studentenhuis>
<studentenhuizen>
<adres>Aalbeeksesteenweg</adres>
<huisnr>19</huisnr>
<gemeente>KORTRIJK</gemeente>
<aantal_kamers>14</aantal_kamers>
</studentenhuizen>
</studentenhuis>
My object
function StudentenKot(adres, huisnr, gemeente, aantalkamers){
this.adres = adres;
this.gemeente = gemeente;
this.huisnr = huisnr;
this.aantalSlaapkamers = aantalkamers;
};
Load xml file:
$.ajax({
type: "GET",
dataType: "xml",
url:url,
success: function (xml) {
studentenhuis = new Array();
$(xml).find("studentenhuizen").each(function () {
studentenhuis.push(new StudentenKot(this.adres, this.huisnr, this.gemeente, this.aantal_kamers));
});
$.each(studentenhuis, function (i) {
$(".studentenkoten").append("<div class='gemeente'>" + studentenhuis[i].adres + "</div>");
});
}
});
When added to the <div class="gemeente"> it says "undefined".
This worked before, but it says [Object object] now
alert($(xml).find("adres"));
this.adres, this.huisnr, …expect to be in thateachloop?thisis an XML node, isn't it?console.log(studentenhuis[i])in your lasteachloop to see the structure of it. Chances are you're just missing a key identifier or something trivial like thataantalSlaapkamers: undefined adres: undefined gemeente: undefined huisnr: undefined __proto__: Object