简体   繁体   English

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

[英]Getting list data from SharePoint 2010 site using Jquery

I am trying to get list data from sharepoint site using JQuery, but have got nothing returned yet, no errors in firebug either.我正在尝试使用 JQuery 从 sharepoint 站点获取列表数据,但还没有返回任何内容,firebug 中也没有错误。 Any clue what is wrong?任何线索有什么问题?

<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);
    });
}

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 . 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.我建议您尝试一下,因为您不必做太多工作。

I strongly suggest that you use the client object model instead of the Web services.我强烈建议您使用客户端 object model 而不是 Web 服务。 Much richer functionality and much, much easier to use.更丰富的功能,更容易使用。

The Client Object Model and jQuery客户端 Object Model 和 jQuery

If you really want to use the Web services, then I suggest you check out the SPServices project .如果您真的想使用 Web 服务,那么我建议您查看SPServices 项目

You should handle the ajax success event, not the complete event.您应该处理 ajax success事件,而不是完成事件。 The complete event doesn't have that signature.完整的事件没有那个签名。

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

complete(jqXHR, textStatus)完成(jqXHR,文本状态)

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

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干杯

Put the processResult function within $(documnet).ready and checkprocessResult function 放入$(documnet).ready并检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JavaScript和jQuery获取超链接字段/列以从SharePoint列表中将数据显示为超链接 - Getting a hyperlink field/column to display data as a hyperlink from a SharePoint List, using JavaScript and jQuery 使用JavaScript从Sharepoint 2013获取列表数据 - Getting List data from Sharepoint 2013 using javascript 如何使用Jquery检索Sharepoint List数据 - How Retrieve Sharepoint List data using Jquery 获取Sharepoint列表2010的部分项目计数 - Getting partial Item Count of Sharepoint list 2010 在Sharepoint 2010中使用Jquery隐藏下拉列表 - Hide drop list with Jquery in Sharepoint 2010 为什么jquery对于Chrome中的Sharepoint 2010网站有效,但对IE不起作用? - Why does jquery work for a Sharepoint 2010 site in Chrome but not IE? 如何在SharePoint 2010网站上为预览窗格编写JavaScript / jQuery? - How to write JavaScript/jQuery for preview pane on SharePoint 2010 site? 是否可以使用REST API将项目添加到Sharepoint 2010中的站点级列表? - Is it possible to add an item to a site level list in Sharepoint 2010 with REST API? 在SharePoint 2010中使用jQuery有条件地隐藏内容 - Hiding content conditionally using jQuery in SharePoint 2010 如果条件为false,则防止在SharePoint 2010中使用jquery列出新表单的默认设置 - if conditions is false then prevent default in SharePoint 2010 List new form using jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM