Im having a variable ‘multi’ , the same name i used within the js file. I need to set a value to the variable within my aspx page and pass it on to the javascript file. Couldnt find any help.
aspx script code
var itemdata = [];
var multi;
//var plot;
$(document).ready(function () {
$.ajax({
type: "POST",
url: "ChartBinder.asmx/BindChart",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
//alert(multi);
var resultObj = $.parseJSON(response.d);
multi = resultObj;
// alert(resultObj.Pie);
multi.Trend = resultObj.Trend;
//alert(multi.Trend);
$.getScript('Scripts/highcharts.src.js', function () {
DrawPie(resultObj.Pie);
DrawTrend(resultObj.Trend);
// do something here
});
},
error: function (msg) {
alert("Error");
}
});
});
js script
(function () {
var seriesCount = window.multi.Trend.length;
var newcolors = [];
for (i = 0; i < seriesCount; i++) {
newcolors[i] = multi.Trend[i].color;
}
})
multishould be in scope globally for use within that your include because you have declared it inGlobalscope i.e the top of the document outside of a function block.Try changing
to
Off Topic:
You don’t need to do the
multi.Trend = resultObj.Trend;assignment as you have already donemulti = resultObj;.