How to access SharePoint list data in Javascript

Source: Internet
Author: User

There is a good solution in SharePoint2010 (see 文sharepoint SharePoint client programming series http://www.jb51.net/article/27198.htm), but in SharePoint2007 is not so easy to use, specific problem analysis, this article is about how to access SharePoint data through WebService in JavaScript.

First you need to download the JavaScript API package from this (http://darrenjohnstone.net/download/12)

References JS. There are two libraries in it. One package is the processing core library SPAPIcore. js, And the other package provides the interface SPAPI_Lists.js for most calls.

<Script src = "SPAPI_Core.js"> </script>
<Script src = "SPAPI_Lists.js"> </script>
The most common interface method is getListItems (listName, viewName, query, viewFields, rowLimit, queryOptions, webID)

The following is a problem that occurs frequently during SPD custom development and obtains user information:
Copy codeThe Code is as follows:
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
);

You can obtain relevant information by processing the returned XML file.
Copy codeThe Code is as follows:
If (items. status = 200)
{
Var rows = items. responseXML. getElementsByTagName ('z: row ');
If (rows. length = 1)
{
Var dep = rows [0]. getAttribute ('oss _ Department ');
Return rows [0]. getAttribute ('oss _ Department ');
}
}

This method is called to send requests synchronously. In addition, if you want to know more about the attributes and values during debugging, you can use alert (items. responseText) to view the returned results.

Refer:

Http://darrenjohnstone.net/2008/07/22/a-cross-browser-javascript-api-for-the-sharepoint-and-office-live-web-services/

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.