0

My requirement is:

To pass listnames as an array to a method and concatenate the result after each success.

The problem is I'm not able to concatenate the result from the previous ajax call

handleClick = (ListName) => {
    var reactHandler = this;  

  jquery.ajax({ 

      url: this.props.siteUrl+ "/_api/web/lists/getbytitle('" + ListName + "')/items" , 

      type: "GET", 

      headers:{'Accept': 'application/json; odata=verbose;'},


      success: function(resultData) { 

        ///logic???


       });

          }


      }, 

      error : function(jqXHR, textStatus, errorThrown) { 

      } 

  });

  }
0

finally found the way to get list items.

var reactHandler = this; 
var listname = ["Asset Approval", "RemoteLists","testList","documentList"];

var i=0;
var itemArrays = {};

var feedPromises = [];
for (let index = 0; index < listname.length; index++){
    //start the process to get all the feeds and save their ajax promises into an array
    feedPromises.push(test(listname[index]));
}
function test(ListName) {


  //alert("getfeed ")
  return  jquery.ajax({
    url: reactHandler.props.siteUrl+ "/_api/web/lists/getbytitle('" + ListName + "')/items" ,

    type: "GET", 

    headers:{'Accept': 'application/json; odata=verbose;'},

      success: function (resultData) {


              itemArrays[i] = resultData.d.results;

               ++i;

      }, 

  error : function(jqXHR, textStatus, errorThrown) { 

  }
  });
}
var listData;
var flag=true;
// wait until all the feeds return data to continue
jquery.when.apply(this, feedPromises)
.done(function(){
    // when all the data calls are successful you can access the data via

    for (let index = 0; index < listname.length; index++) {

   alert(itemArrays[index])


    }

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.