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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6631181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:20:14  来源:igfitidea点击:

Getting list data from SharePoint 2010 site using Jquery

javascriptjquerysoapsharepoint-2010

提问by Chen Zhong

I am trying to get list data from sharepoint site using JQuery, but have got nothing returned yet, no errors in firebug either. Any clue what is wrong?

我正在尝试使用 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);
    });
}

回答by Marc D Anderson

Right after your line

就在您的线路之后

function processResult(xData, status) { 

add an alert like this:

添加这样的警报:

alert(xData.responseText);

That will show you what is coming back from the call to GetListItems.

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

also, you should change this line:

此外,您应该更改此行:

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

to this:

对此:

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

which is more reliable across browsers. (See my blog post: http://sympmarc.com/2009/11/08/sharepoints-web-services-jquery-and-the-zrow-namespace-in-safari-and-chrome/)

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

As Rob Windsor mentions in his answer, I've got many of the SharePoint Web Services wrapped with jQuery to make them easier to use in my SPServices jQuery library. I'd suggest you try it out, as you won't have to do as much work.

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

回答by Rob Windsor

I strongly suggest that you use the client object model instead of the Web services. Much richer functionality and much, much easier to use.

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

The Client Object Model and jQuery

客户端对象模型和 jQuery

If you really want to use the Web services, then I suggest you check out the SPServices project.

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

回答by ScottE

You should handle the ajax successevent, not the complete event. The complete event doesn't have that signature.

您应该处理 ajaxsuccess事件,而不是 complete 事件。完整的事件没有那个签名。

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

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

complete(jqXHR, textStatus)

完成(jqXHR,文本状态)

success(data, textStatus, jqXHR)

成功(数据,文本状态,jqXHR)

回答by Edgar Villegas Alvarado

Perhaps you have a same-origin policy violation.

也许您违反了同源策略。

Check that the current url where runs the script, begins with http://my_site/

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

Hope this helps. Cheers

希望这可以帮助。干杯

回答by jg1

Put the processResultfunction within $(documnet).readyand check

processResult函数放入$(documnet).ready并检查