How to use SPAPI in Sharepoint
Really this is a great api of Javascript for Sharepoint
Lets start ..............
First we need two SPAPI file and one Jquery file
1) SPAPI_Core.js
2) SPAPI_Lists.js
3) jquery-1.5.1.js
and also Jquery file that you can get very easily. These three file you need to add in your file after that you can work. I m just giving one example how to get data from list and display through alert box.
<------Start----------------->
<html>
<head>
<script src="jquery-1.5.1.js"></script>
<script src="SPAPI_Lists.js"></script>
<script src="SPAPI_Core.js"></script>
<script type="text/javascript">
$(function (){
var lists = new SPAPI_Lists('ListLocation');
var items = lists.getListItems('ListName');
if (items.status == 200)
{
var rows = items.responseXML.getElementsByTagName('z:row'); // Get only list rows
for (var i=0; i<rows.length; i++)
{
var newid =rows[i].getAttribute('ows_ID');
alert(newid);
//List's field names are prefixed with 'ows_' when converted
}
}
else
{
alert('There was an error: ' + items.statusText);
}
});
</script>
</head>
<body>
<div>
<p>
Change path, list name, fields name and then it will work else give u error.......!
</p>
</div>
</body>
</html>
<-------------End------------>
No comments:
Post a Comment