0

I am a new SharePoint developer, and I am finding SharePoint to be a bit difficult. I have been looking for a way to query a SharePoint 2013 list with JavaScript for a while now, and I can't find an clear solutions.

What I am trying to do is to validate if an entered email address exists in my "subscription list". This will occur every time a certain button is clicked. The validation will happen in a modal view which I am yet still trying to create.

Some of the posts I have seen online talk about the sp.js file which I am not sure where I will find. Also, are the some good tutorials for SharePoint 2013.

1

3 Answers 3

2

Include SP.js, SP.Runtime.js and Microsoft.Ajax.js. Your JavaScript could look like this (using jQuery for convenience ...):

$.ajax({
  url: "http://<DomainName>/<PathToWeb>/_api/web/lists/GetByTitle('<ListTitle>')/items",
  type: "GET",
  headers: {
    "accept": "application/json;odata=verbose",
  },
  success: function(data){
      $.each(data.d.results, function (key, value) {
        $("#ParentContainerId").append($("<pre></pre>")
                              .html(value.Title);
      });
  },
  error: function(error){
    alert(JSON.stringify(error));
  }
});

n.b. If you need other fields than ID or Title, you must include them in a select statement at the end of the request URL using the InternalName as described here:

?$select=FileLeafRef

There are more examples on how to retrieve and work with SharePoint ListItems using REST in the MS TechNet and a good documentation of the REST API in MSDN.

Sign up to request clarification or add additional context in comments.

1 Comment

Please add more details to your answer, even if it is copy-pasted and quoted from that link. A short description would work also. As it is not it is a link-only answer and it is not admitted.
1

There are two major ways to query SharePoint data using javascript: 1) Javascript Client Object Model. In this case you will need to add SharePoint javascript libraries which are located on SharePoint server in layouts virtual folder. 2) REST services.

Comments

0

I used SPServices successfully for years (although I don't do Sharepoint currently and I have only worked with 2007/2010).

I believe you are looking for GetListItems more specifically.

Comments

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.