<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(functionName, "sp.js"); //this is necessary to ensure the library is loaded before function triggered
var namedListItem;
function functionName() {
var clientContext = SP.ClientContext.get_current();
//or use the syntax below for accessing a list that may not reside in the current site
//var clientContext = new SP.ClientContext(rootUrl);
var myList = clientContext.get_web().get_lists().getByTitle('myList'); //actual list name here
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(''); //caml statement goes here between the single quotes
namedListItem = myList.getItems(camlQuery);
clientContext.load(namedListItem);
//or use below to specify to load only the required properties for better performance
//clientContext.load(namedListItem, 'Include(field1, field2)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = namedListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nField1: ' + oListItem.get_item('field1') + ', Field2: ' + oListItem.get_item(' field2'); //replace field1 & field2 with actual column names
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>