I am attempting to transfer variables from an XML file to the parent class in JavaScript. The code follows Object-Oriented Programming principles, with a class named "example" and a method called getData().
The issue I'm encountering is that the AJAX call only returns integer values, not string ones - which seems quite strange.
(modified as per T.J. Crowder:)
function example(){
this.b;
this.str;
}
example.prototype ={
getData:function(){
$.ajax({
type: "GET",
url: "Bar.xml",
dataType: "xml",
context: this,
success: function(xml) {
this.b = parseInt($(xml).find('current_madad').text()); //int_from_xml- works!
this.str = $(xml).find('graph_title').text(); //string_from_xml - doesnt work!!
}
})//end ajax
}
};
var c = new example();
c.getData();
The XML file can be found here for further review of the code:
<?xml version="1.0" encoding="utf-8"?>
<root>
<Bars>
<Bar>
<bar_start>1010</bar_start>
<lower_danger_zone>1030</lower_danger_zone>
<mid_safe_zone>1050</mid_safe_zone>
<upper_danger_zone>1150</upper_danger_zone>
<upper_fbdn_zone>1200</upper_fbdn_zone>
<bar_range>200</bar_range>
<ideal_range>5</ideal_range>
<current_madad>1115</current_madad>
</Bar>
</Bars>
<Bars_Desc>
<Bar>
<graph_title>פוזיצית אפריל</graph_title>
<lower_fbdn_zone_Desc>תחום אסור תחתון תיאור</lower_fbdn_zone_Desc>
<lower_danger_zone_Desc>תחום מסוכן תחתון תיאור</lower_danger_zone_Desc>
<mid_safe_zone_Desc>תחום בטוח אמצעי תיאור</mid_safe_zone_Desc>
<mid_safe_ideal_zone_Desc>תחום בטוח פקיעה אידיאלית תיאור</mid_safe_ideal_zone_Desc>
<upper_danger_zone_Desc>תחום מסוכן עליון תיאור</upper_danger_zone_Desc>
<upper_fbdn_zone_Desc>תחום אסור עליון תיאור</upper_fbdn_zone_Desc>
</Bar>
</Bars_Desc>
</root>