I have inserted the following javascript into a masterpage, however I am getting this error:
Uncaught TypeError: undefined is not a function
I believe that this might be because the SP JS files are not correctly loaded at that time, I still see them on F12 after the page finishes loading.
http://screencast.com/t/Akb7KKpn5p2
My code is as follows:
// A $( document ).ready() block.
$(document).ready(function() {
console.log( "ready!" );
var path = document.location.href
console.log(path);
var clientContext = new SP.ClientContext('http://myservername/centrodeprocesos/procesos');
var oList = clientContext.get_web().get_lists().getByTitle('ImagenesDeFondo');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
'<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
});
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nTitle: ' + oListItem.get_item('Title') +
'\nBody: ' + oListItem.get_item('Body');
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}