2

hi How to access sharepoint list from javascript using ajax? I am getting 404 error everytime.

     var d ="<?xml version=\"1.0\" encoding=\"utf-8\<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Body><GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">
<listName>TEST</listName>
<queryOptions></queryOptions>
<query><Query><Where><Eq><FieldRef Name=\"Title\"/><Value Type=\"Text\">title</Value></Eq></Where></Query></query>
</GetListItems>
</soap:Body></soap:Envelope>";

Can someone check if Soap envelope is correct?

1
  • Using single quotes (') to enclose that string would save you the trouble of having to escape all the internal quotes. Commented Feb 8, 2011 at 19:17

1 Answer 1

4

It would be easyer to use a library instead of forging soap envelopes yourself. Try SPServices, a jQuery library for SharePoint web services.

Then you just do something like:

<script type="text/javascript" src="filelink/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="filelink/jquery.SPServices-0.5.4.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });
});
</script>
<ul id="tasksUL"/>

Nice!

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

2 Comments

I agree. SPServices is really easy to use. This should be marked as the answer. And because it is JQ, it also allows for other fun things like autocomplete, etc.
if you are using jquery 1.7 and above the syntax cannot work anymore, see sympmarc.com/2011/11/23/…. Please use $(xData.responseXML).SPFilterNode("z:row").each(function() { }); instead.

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.