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/