How to access the list data using javascript in ShaerPoint 2007

When we custom SharePoint, we maybe limited to access the server or we can’t deploy our solution.So many developments just could be completed in client. In SharePoint 2010, we could use the Client Object to resolve this problem, but in SharePoint 2007, how should we do?

This article will resolve this problem. We could use javascript to invoke the WebService to access the list data of SharePoint 2007.

First, we will download the package JavaScript SharePoint API. Then we should reference the JS. One is the core library:SPAPIcore.js, another is the package SPAPI_Lists.js which supply many interface you could invoke.

<script src="SPAPI_Core.js"></script>
<script src="SPAPI_Lists.js"></script>

The interface methods which we often use is: getListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, webID)

Below is the requirement when we custom SharePoint : get the user’s 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
);





We could handle the returned XML file to get the information:




if (items.status == 200)
{
var rows = items.responseXML.getElementsByTagName('z:row');
if (rows.length == 1)
{
var dep = rows[0].getAttribute('ows_Department');
return rows[0].getAttribute('ows_Department');
}
}







This method send the request is synchronization, If you want to know the property and values when you debug, you could view the returned result by alert(items.responseText).



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



You could contact to me by Email: jieiyan@gmail.com