简体   繁体   中英

How to retrieve a sharepoint announcement list in HTML Page

I need help with pulling a sharepoint announcement list using an HTML page. I have tried numerous examples from various sites, however none seem to work at all. So I am obviosly clueless or not understanding something....

The HTML page that will pull the sharepoint announcement list will reside at [http://mysite/Announce.html]

The Sharepoint site is located at [http://companyweb/Lists/Announcements/AllItems.aspx]

I would like to have the html page ( Announce.html ) simply list the Date , Title and Body of the announcement.

I know there is jquery methods etc...but I can't seem to figure this out.

Any help would be greatly appreciated. I am a novice programmer so any detailed examples would be great.

This is what I have tried so far and nothing displays

Test.html

<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"/>

I created a JS Library for Sharepoint: http://aymkdn.github.io/SharepointPlus/

That could be someway easier to use (example not tested) :

<script type="text/javascript" src="filelink/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="filelink/sharepointplus-3.0.4.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
  $SP().list("Announcements").get({fields:"Title,Body,Created",orderby:"Created DESC"}, function(data) {
    var html="",d;
    for (var i=data.length; i--;) {
      d = $SP().toDate(data[i].getAttribute("Created")); // convert the Created date to a Javascript Date Object
      d = (d.getMonth()+1) + '/' + d.getDate() + '/' + d.getFullYear();
      html += "<li>" + data[i].getAttribute("Title") + " (" + d + ")</li>";
    }
    $("#tasksUL").append(html);
  })
})
</script>

This the code that I use to retrieve data from SP lists using script, I have used it on 2010 and 2013 version and always worked for me.

Set your Sharepoint URL at SPURL, and change the Web Pages

var SPURL="https://www.yoururl.com"
$(document).ready(function() {
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>Web Pages</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Title' /> \
                       </ViewFields> \
                    </viewFields> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: SPURL+"/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});

var names = new Array();
var href = new Array();
var iterator;

function processResult(xData, status) {
    $(xData.responseXML).find("z\\:row, row").each(function() {

    names.push($(this).attr('ows_Title'));
    href.push($(this).attr('ows_FileRef'));

    });
    var sorted = new Array();                                   
    for (var i=0; i<href.length; i++)
    {
         sorted.push([names[i],href[i]]); 
    }

    sorted=sorted.sort();
    iterator=href.length;
    var liHtml = "";
    for (var i=0; i<iterator; i++)
    {
        var name = sorted[i];
        var hrf = sorted[i]
        names[i]=(name[0].split("-"))[1];
        href[i]=(hrf[1].split("/"))[1];

        liHtml += "<li class='static'>" +
                "<a class='static menu-item' accesskey='1' href='"+href[i]+"'>" +
                "<span class='additional-background'>" +
                    "<span class='menu-item-text'>"+names[i]+"</span>" +
                "</span>" +
                "</a>" +
                "</li>";        
    }

    $("#SPData").append(liHtml);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM