码迷,mamicode.com
首页 > Web开发 > 详细

Jquery Call WebDav

时间:2014-05-31 00:50:26      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

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

 

bubuko.com,布布扣
<!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>
bubuko.com,布布扣

 

Jquery Call WebDav,布布扣,bubuko.com

Jquery Call WebDav

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/Edwinzq/p/3761941.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!