jquery - Having trouble getting to the JSON response after promises resolve -
i'm sorry, guys. hate having ask question; promise, i've been through many other questions tangentially related patience allow.
following code following questions:
- jquery when each completed, trigger function
- jquery ajax solution inside each() loop
- how return response asynchronous call?
i've got following:
var xhr = []; //this parses selections on screen, which, in turn, informs url inside loop. $("#list > input:checkbox:checked").each(function(){ result = []; var list = $(this).val(); xhr.push($.ajax({ type:'get', url:"https://a-place.com/subsite/webapp/_api/web/lists/getbytitle('"+list+"')/items?$select=" + select + "&$filter=" + filter + "&$expand=" + expand + "&$top=10000", datatype: "json", headers: {accept:"application/json;odata=verbose"}, complete:function(data){} })); }); $.when(xhr).then(function(data){ console.log(data); }); no matter do, i'm ever getting promises inside .when.then construction. can't them, trying access responsejson property, actual objects are, nothing. i've tried adding return statement inside complete callback function, doesn't appear change what's getting pushed xhr array.
ideally, supposed return bunch of list items 1 or more sharepoint lists match selected options , put matched items single array can stuff with.
edit
hmm. ok, based on advice, i've tried:
success:function(data){} and
success:function(data){return data.d.results;} and nothing changes in console regardless of whether use $.when.then or .done.
thanks in advance.
you can try collecting results in success callback, , use afterwards in 'then' function callback:
var results = []; ... success: function(data){ results.push(data.d.results); } ... $.when(xhr).then(function(){ // here should have results filled in console.log(results); });
Comments
Post a Comment