​Disp​laying list information with SPServices

SPServices is a client-side jQuery library that you can use to read and write data to SharePoint lists with javascript. We are using version 0.6.2 of the SPServices library. Both the SPServices and jQuery (1.6.4) libraries are included in the master page, you don't need to add them again to your custom code.​

Let's say you have the following list in your site, it has two columns called "Fruit" and "Color" containing the names of fruit and their corresponding colors:​​

We can read the list and write its contents to a list using the following javascript code:


$().SPServices({
  operation: "GetListItems",
  async: false,
  listName: "Fruit",
  CAMLViewFields: "<ViewFields><FieldRef Name='Fruit' /><FieldRef Name='Color' /></ViewFields>",
  completefunc: function (xData, Status) {
    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
      var liHtml = "<li>" + $(this).attr("ows_Fruit") + ", " + $(this).attr("ows_Color") + "</li>";
      $("#fruitlist").append(liHtml);
    });
  }
});

This is what we get when we run the code: