I have an AJAX call to sharepoint (shown below).
function GetProductIDSforActiveQuote() {
var arr = new Array();
$().SPServices({
operation: "UpdateListItems",
listName: "Quotes",
ID:quoteID,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
arr = $(this).attr("ows_Products").split(',');
});
}
});
return arr;
}
I’m trying to return an Array, but get an empty array at the end. I can verify by putting a console log inside the completefunc block, that values are being returned properly.
AJAX calls are asynchronous. This means that by the time you hit the line
return arr, thecompleteFunchasn’t necessarily been invoked yet.Could you modify the code so it takes a callback function which is provided the array? Like this:
In the callback function, you could then process the array however you needed.