I am using jquery .promise for the first time and I am doing something totally wrong. i get a syntax error. Please help. I have a SharePoint site and I am using REST API to query a list. My goal is to get a count of ticket types and to create a jqplot chart. I get a syntax error when i try to use jquery .promise but it looks fine. Any help would be much appreciated.
var ticketArray = new Array();
var myData = new Array();
var i = 0;
$.getJSON("../practice/_vti_bin/ListData.svc/TicketType", function(data) {
//iterate through all returned Ticket list items and store in an object
$.each(data.d.results, function(i, result) {
//get item property
var TicketObj = {};
TicketObj.TicketType = result.Title;
TicketObj.Count = 0;
ticketArray[i] = TicketObj;
i++;
});
promise = $.ajax({
type: "GET",
//dataType: "json",
url: "../practice/_vti_bin/ListData.svc/TicketingSystems?$select=TypeOfTicket",
cache: false
});
promise.done(function(data) {
//success : function(data) {
//iterate through all returned Ticket list items and get count
$.each(data.d.results, function(i, result) {
for (var x = 0; x < ticketArray.length; x++) {
//console.log("Ticket Type: "+result.TypeOfTicket);
if (ticketArray[x].TicketType == result.TypeOfTicket) {
ticketArray[x].Count += 1;
console.log("Ticket Count: " + ticketArray[x].Count);
}
}
}); //each()
)
};
promise.done(function(data) {
$.each(ticketArray, function(index, value) {
myData.push([ticketArray[index].TicketType, ticketArray[index].Count]);
});
)
};
//}
var plot1 = jQuery.jqplot('chart1', [myData], {
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true
}
},
legend: {
show: true,
location: 'e'
}
}); //end plot1