1.Create a Custom List Name as "Emp" and Create a below Column Name
FirstName - Single Line Text
LastName-Single Line Text
Location-Single Line Text
2.Create one Content Editor WebPart and paste the below code
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript" src="https://github.com/douglascrockford/JSON-js/blob/master/json2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
GetEmpListItemData();
});
function GetEmpListItemData() {
// get Emp list data
var datarows = [];
$().SPServices({
operation: "GetListItems",
webURL:"https://Site Collection Url/sites/TestSite",
async: false,
listName: "Emp",
CAMLViewFields: "<ViewFields><FieldRef Name='Title'/><FieldRef Name='FirstName'/><FieldRef Name='LastName'/><FieldRef Name = 'Location'/></ViewFields>",
CAMLQuery: "<Query><OrderBy><FieldRef Name='ID' Ascending='True'/></OrderBy></Query>",
completefunc: function(xData, Status) {
var listitemrows = $(xData.responseXML).find("z\\:row, row");
$(listitemrows).each(function() {
var Id = $(this).attr("ows_ID");
var Title = $(this).attr("ows_Title");
var FirstName = $(this).attr("ows_FirstName");
var LastName = $(this).attr("ows_LastName");
var Location = $(this).attr("ows_Location");
datarows.push({Id: Id, Title: Title,FirstName: FirstName,LastName: LastName,Location: Location});
});
}
});
var myJsonString = JSON.stringify(datarows);
alert(myJsonString);
for (var arrayIndex in datarows) {
var Id=datarows[arrayIndex].Id;
alert(Id);
}
}
</script>
FirstName - Single Line Text
LastName-Single Line Text
Location-Single Line Text
2.Create one Content Editor WebPart and paste the below code
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript" src="https://github.com/douglascrockford/JSON-js/blob/master/json2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
GetEmpListItemData();
});
function GetEmpListItemData() {
// get Emp list data
var datarows = [];
$().SPServices({
operation: "GetListItems",
webURL:"https://Site Collection Url/sites/TestSite",
async: false,
listName: "Emp",
CAMLViewFields: "<ViewFields><FieldRef Name='Title'/><FieldRef Name='FirstName'/><FieldRef Name='LastName'/><FieldRef Name = 'Location'/></ViewFields>",
CAMLQuery: "<Query><OrderBy><FieldRef Name='ID' Ascending='True'/></OrderBy></Query>",
completefunc: function(xData, Status) {
var listitemrows = $(xData.responseXML).find("z\\:row, row");
$(listitemrows).each(function() {
var Id = $(this).attr("ows_ID");
var Title = $(this).attr("ows_Title");
var FirstName = $(this).attr("ows_FirstName");
var LastName = $(this).attr("ows_LastName");
var Location = $(this).attr("ows_Location");
datarows.push({Id: Id, Title: Title,FirstName: FirstName,LastName: LastName,Location: Location});
});
}
});
var myJsonString = JSON.stringify(datarows);
alert(myJsonString);
for (var arrayIndex in datarows) {
var Id=datarows[arrayIndex].Id;
alert(Id);
}
}
</script>
No comments:
Post a Comment