Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Javascript to display sharepoint list items on page load
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
window.onload = function() {
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
}
</script>
<div id="test">
</div>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<SharePointWebControls:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="False" />
<script src="/cs/Style Library/CustomStyles/scripts/jquery.tools.min.js" type="text/javascript"></script>
<script type="text/javascript">
function ViewItem()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Service Basket');
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, 'Include(Title)');
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
var TextFiled = "";
var ListEnumerator = this.allItems.getEnumerator();
$('#test').append('<ul>');
while(ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
$('#test').append('<li>'+currentItem.get_item('Title') + '</li>\n');
}
$('#test').append('</ul>');
}
function failed(sender, args) {
alert("failed. Message:" + args.get_message());
}
</script>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
$(document).ready(function(){
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
})
</script>
<div id="test">
</div>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
$(function(){
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
})
</script>
<div id="test">
</div>
</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment