I am trying to return an object through the _fail callback (Yes, this is meant to run the fail callback), but failSeries is returning as undefined in the console. Any ideas?
var ChartModule = (function ( $, HC, HA, window, undefined) {
//Define public object
var pub = {};
//Private methods
var _getChartData = function (URL, sendData) {
var xhrObject = $.ajax({
url: URL,
type: "POST",
data: sendData,
success: function (result) { },
error: function (jqXHR, textStatus, errorThrown) {}
});
_chartDataResponse(xhrObject);
};
var _done = function (data, textStatus, jqXHR) {
var seriesObject = $.parseJSON(data);
return seriesObject;
};
var _fail = function(){
var failSeries = [];
var seriesData = {
data: [{y: 7, id: 'pointAssets', color: '#5c8fb8'}, {y:10, id: 'pointLiabilities', color: '#bb77b5'}, {y:-3, id: 'pointResult', color: '#cc5971'}],
};
failSeries.push(seriesData);
return failSeries;
};
var _chartDataResponse = function(xhrObject){
xhrObject.then(_done, _fail);
};
var _renderChart = function(renderTo, seriesObject){
console.log("Chart will be rendered to: '" + renderTo + "'");
console.log(seriesObject);
};
//Public methods
pub.getChartData = _getChartData;
pub.renderChart = _renderChart;
return pub;
})(jQuery, Highcharts, HighchartsAdapter, window, undefined);
I am then using my module in the following way in an attempt to view the object that has been returned by either the success or fail callabcks:
$(function(){
var x = ChartModule.getChartData("someURL", {test: "test"});
ChartModule.renderChart("breakdown-chart", x);
});