How to retrieve data from a list in Sharepoint 2013 using oData and JavaScript


/ Published in: JavaScript
Save to your folder(s)

The following code fetches contents of each Title field from the list called "LandingMiddleLinks"


Copy this code and paste it in your HTML
  1. function getTitles() {
  2.  
  3. // begin work to call across network
  4. var requestUri = _spPageContextInfo.webAbsoluteUrl +
  5. "/_api/Web/Lists/getByTitle('LandingMiddleLinks')/items";
  6.  
  7. // execute AJAX request
  8. $.ajax({
  9. url: requestUri,
  10. type: "GET",
  11. headers: { "ACCEPT": "application/json;odata=verbose" },
  12. success: function(data){
  13.  
  14. $.each(data.d.results, function(index) {
  15. console.log($(this).attr('Title'));
  16.  
  17. });
  18.  
  19. },
  20. error: function(){
  21. alert("Failed to get title");
  22. }
  23. });
  24. }

Report this snippet


Comments


You need to login to view comments.