Project Server 2016 RestAPI调用测试

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta name="WebPartPageExpansion" content="full"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>测试Project Server RestAPI</title>
    <meta http-equiv="X-UA-Compatible" content="IE=10"/>
    <SharePoint:CssRegistration Name="default" runat="server"/>
    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
    <script type="text/javascript">

        requestProjectApi("","/sites/pwa/_api/ProjectServer/Projects",function (data) {
            var projectdata_html = "";
            $(data).each(function (index, item) {
                projectdata_html += "<tr>";
                projectdata_html += "<td>"+(index+1)+"</td>";
                projectdata_html += "<td>"+item.Name+"</td>";
                projectdata_html += "<td>"+item.CreatedDate+"</td>";
                projectdata_html += "</tr>";
            });
            $("#tb_projectdata").html(projectdata_html);
        })

        function requestProjectApi (postData,postUrl,callBack) {
            $.ajax({
                url: postUrl,
                type: "GET",
                contentType: "application/json",
                data: postData,
                headers: {
                    "Accept": "application/json; odata=verbose",
                },
                complete: function (xhr, textStatus) {
                    if (xhr.status == 200) {
                        var jsondata = JSON.parse(xhr.responseText).d.results;
                        if(callBack){
                            callBack(jsondata);
                        }
                    }
                },
                error: function (data, errorCode, errorMessage) {
                }
            });
        }
    </script>
</head>
<body>
<form id="form1" runat="server">
    <table>
        <thead>
        <tr>
            <th>序号</th>
            <th>项目名称</th>
            <th>创建日期</th>
        </tr>
        </thead>
        <tbody id="tb_projectdata">
        </tbody>
    </table>
</form>
</body>
</html>

 

 

posted on 2017-07-17 11:08  larryle  阅读(264)  评论(1编辑  收藏  举报