How to access SharePoint list data in JavaScript

Source: Internet
Author: User

When you make a SharePoint order, you often encounter problems with the limitations of your development tools, such as the usual companies restricting access to servers and deployment, and many of the developments are only available on the client side. There is a good solution in SharePoint2010 (see the http://www.cnblogs.com/johnsonwong/archive/2011/05/13/2044993 SharePoint Client Programming series for details). HTML), but in the SharePoint2007 is not so easy to use, specific problem analysis, this article is to solve the problem of how to access SharePoint data in JavaScript through WebService.

First you need to download the JavaScript API package from here (HTTP://DARRENJOHNSTONE.NET/DOWNLOAD/12)

Refer to the second JS, which has two libraries, one package is to deal with the core library Spapicore.js, another package provides most of the calls to the interface Spapi_lists.js

<script src= "Spapi_core.js" ></script>
<script src= "Spapi_lists.js" ></script>
The most commonly used interface methods are GetListItems (ListName, viewName, query, ViewFields, Rowlimit, Queryoptions, WebID)

The following is a common problem encountered during the SPD custom development process, obtaining user information:

function Getcurrentuserstat ()
{
    var lists = new spapi_lists (');
    var items = lists.getlistitems (
    ' UserInfo ',
    ', ',
    ' <query><where><eq><fieldref Name = "ID"/><value type= "Counter" > ' + _spuserid    + ' </Value></Eq></Where></Query> ', Query
    ' <viewfields><fieldref name= ' Department '/></viewfields> ',
   1,//Rowlimit
   ' '//Queryoptions
);

Information can be obtained by processing the returned XML file

if (items.status = =)
{
    var rows = items.responseXML.getElementsByTagName (' Z:row ');
    if (rows.length = = 1)
    {  
        var dep = Rows[0].getattribute (' ows_department ');
        Return Rows[0].getattribute (' ows_department ');
    }

The call to this method is to send the request synchronously, and if you want to learn more about the value of the property when you debug it, you can view the returned results through alert (items.responsetext).

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.