使用Jquery从SharePoint 2010站点获取列表数据

Getting list data from SharePoint 2010 site using Jquery

本文关键字:获取 列表 数据 站点 2010 Jquery SharePoint 使用      更新时间:2023-09-26

我正在尝试使用JQuery从sharepoint网站获取列表数据,但没有任何返回,也没有firebug错误。有什么问题吗?

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(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>Action Items</listName> '
                    <viewFields> '
                        <ViewFields> '
                           <FieldRef Name='Title' /> '
                       </ViewFields> '
                    </viewFields> '
                </GetListItems> '
            </soapenv:Body> '
        </soapenv:Envelope>";
    $.ajax({
        url: "http://my_site/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset='"utf-8'""
    });
});
function processResult(xData, status) {
    $(xData.responseXML).find("z'':row").each(function() {
        console.log("aaaa");
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
    });
}

行后

function processResult(xData, status) { 

添加如下提示:

alert(xData.responseText);

这将显示调用getlisttitems返回的内容。

同样,你应该改变这一行:

 $(xData.responseXML).find("z'':row").

:

$(xData.responseXML).find("[nodeName='z:row']")

在浏览器中更可靠。(见我的博客:http://sympmarc.com/2009/11/08/sharepoints-web-services-jquery-and-the-zrow-namespace-in-safari-and-chrome/)

正如Rob Windsor在他的回答中提到的,我已经用jQuery包装了许多SharePoint Web服务,使它们更容易在我的SPServices jQuery库中使用。我建议您尝试一下,因为您不需要做太多的工作。

我强烈建议您使用客户机对象模型而不是Web服务。更丰富的功能,更容易使用。

客户端对象模型和jQuery

如果您真的想使用Web服务,那么我建议您查看SPServices项目。

您应该处理ajax success事件,而不是完整的事件。完整的事件没有这个签名。

http://api.jquery.com/jQuery.ajax/

完成(jqXHR textStatus)

success(data, textStatus, jqXHR)

可能您违反了同源策略。

检查当前运行脚本的url是否以http://my_site/

开头

希望这对你有帮助。欢呼声

processResult函数放在$(documnet).ready中,检查