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) { 

      } 

  });

  }
1

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.