开发者

accessing sharepoint list using javascript

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><GetLi开发者_JAVA技巧stItems 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?


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜