Jquery Call WebDav

最近研究了一下WebDav,尝试了一下用Jquery.ajax 发生请求访问WebDav. 代码如下:

 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test WebDav</title>
    <script src="Scripts/jquery-1.7.1.min.js"></script>
    <script>
        $(document).ready(function () {
            var requestData = "<?xml version=\"1.0\" ?> " +
        "<D:propfind xmlns:D=\"DAV:\">" +
                "<D:allprop/>" +
        "</D:propfind>"
            $.ajax({
                url: http://localhost/, type: "PROPFIND", contentType: "text/xml",
                data: requestData,
                dataType: "XML",
                username: "test",
                password: "test",
                headers:{depth:"1"},
                success: function (data) {
                    var filenodes = data.childNodes[0].childNodes;
                    var len = filenodes.length;
                    for (var i = 0; i < len; i++) {
                        if (filenodes[i].childNodes.length > 1 && filenodes[i].childNodes['1'].childNodes.length > 1) {
                            var propStat = filenodes[i].childNodes['1'].childNodes['1'];
                            var displayName = propStat.getElementsByTagName("D:displayname");
                            if (displayName.length > 0) {
                                var td = "<tr><td>" + displayName['0'].textContent + "</td>";
                                var modifyData = propStat.getElementsByTagName("D:getlastmodified");
                                if (modifyData.length > 0) {
                                    td = td+"<td>"+modifyData[0].textContent+"</td>";
                                }
                                var isDirectory = propStat.getElementsByTagName("D:iscollection");
                                if (isDirectory.length > 0) {
                                    td = td + "<td>"+isDirectory[0].textContent + "</td>"
                                }
                                td = td + "</tr>";
                                $("#tblBody").append(td)
                            }
                        }
                    }

                    $("#results").text(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $("#results").text("Error: " + errorThrown)
                }
                
            });
        });
    </script>
</head>
<body>

    <textarea id="results"></textarea>
    <table>
        <thead>
            <tr>
                <th>Display Name</th>
                <th>Modified Data</th>
                <th>Is Directory</th>
            </tr>
        </thead>
        <tbody id="tblBody">
           
        </tbody>
    </table>
</body>
</html>

 

转载于:https://www.cnblogs.com/Edwinzq/p/3761941.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值