Sunday 17 February 2013

calling REST with Jquery from sharepoint 2010

I will show how to call REST service with JQUERY to fetch data from sharepoint list.

I have one sharepoint list called Employee1 which has 2 columns(Ename and Contact).

Include these 2 scripts:

<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
Next write following code- 

<script type="text/jscript" language="jscript">$(document).ready(function () {


$.getJSON('http://URL/_vti_bin/ListData.svc/Employee1', function (data) {
//alert(data);
var count = 0;
$.each(data.d.results, function (i, result) {
//alert(result);
var Ename= data.d.results[i].Ename
var Contact= data.d.results[i].Contact;
html = "<table border=’1′ style=’float: left’><tr><td style=’color:blue’>" + Ename+ "</td><td style=’color:blue’>" + Contact+ "</td></tr></table>";
//html1 = "<table border=’1′ style=’float: left’><tr><td style=’color:blue’>" + title + "</td></tr></table>";
$('#resultarea').append($(html));
});
});
});

</script>

No comments:

Post a Comment