How to make Rest API call synchronous in SharePoint
How to make Rest API call synchronous in SharePoint In this post, I will discuss how we can make a synchronous Rest API call in SharePoint using jQuery. Normally when we do Rest API call using AJAX calls in SharePoint, it executed asynchronously. So it is not possible to know whether the call has been made completely or not. Sometimes you might come across a requirement where you want to execute something after the call has been made complete. Here I will show some ways of make synchronous Rest API call in SharePoint - 1. Using then - getItems().then(getItemsSuccess, getItemsFail); function getItems(){ return $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('ListName')/items", type: "GET", headers: { "accept": "application/json;odata=verbose", } }); } function getItemsSuccess(data){ if(data.d.results.length > 0){ //do something here // } } function getItemsFail(err){ alert(...