I am trying to pass variables from an xml file to the father class in js:
the code is basically OOP js.
The class is example and the method is getData().
the thing is that the ajax call doesn’t return the whole values, just the int ones.. weird, I know.
(changed due to 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 is here. Posted so that you can review that code as well..
<?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>
got it! I am using the data I need and passing it throw a function inside ajax’s success!
getData:function(){
}