var channelsArray = [];
var percentArray= [];
var valueArray= [];
var jsonData,canvas,context;
var colorArray=["#ECD078","#D95B43","#C02942","#542437","#53777A"];
var posX=220;
var posY=60;
var width=55;
var graph=false;
//Webservice Request and Response begins.......................................
$.ajax({
type: "POST",
url: "http://localhost/WebSite1/myservice.asmx/GetData",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(msg) {
if(localStorage.getItem("channels")==null){
jsonData =jQuery.parseJSON(msg.d);
jsonToLocal();
}
var strDisplay = " <table cellspacing='0' id='myTable' " +
" <tr>" +
" <th > Channels </th>" +
" <th> Percentage</th>" +
" <th> Value</th>" +
" </tr>";
for (var i = 0; i < colorArray.length; i++) {
strDisplay = strDisplay +
" <tr style='cursor:pointer;' onclick='javascript:rotateChart("+i+")'>" +
" <td>" + channelsArray[i] + "</a> </td>" +
" <td> " + percentArray[i] + " </td>" +
" <td> " + valueArray[i] + " </td>" +
" </tr>";
}
strDisplay = strDisplay + "</table>";
document.getElementById('DynamicGridLoading').innerHTML = strDisplay;
document.getElementById('myTable').setAttribute("class","datatable");
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
}
});
//Webservice Request and Response ends........................
//converting json data into local storage....
function jsonToLocal(){
for(i=0;i<jsonData.Table.length;i++){
percentArray.push(jsonData.Table[i].toString());
channelsArray.push(jsonData.Table[i].Channels);
valueArray.push(jsonData.Table[i].Value);
}
try {
localStorage.setItem("percentage", percentArray.join(","));
localStorage.setItem("channels",channelsArray .join(","));
localStorage.setItem("value",valueArray.join(","));
}
catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert("Quota exceeded!");
}
}
}
this is my almost entire code…am getting this ‘uncaught’ error in function jsontolocal at percentArray….if i remove this line..other two work fine.. all these arrays are pushing string values inside dem..
my problem was nothing but random and unknown behavior of javascript.. To ensure that this never happens..i found out to follow following things while writing a javascript code -:
these were the mistakes i was making..sometimes it would run..sometimes it would show a random behavior..anyways..my problem is solved