I know there are many posts like mine, but I couldn’t find any answer to why it is not working for me.
Based on that answer: https://stackoverflow.com/a/59340514/17645049
I changed the name of the columns, the list’s name and of course the list’s URL. Running the code gives me the error “Request failed. Unexpected server response data. Null”.
Any suggestion?
Browser: Edge. Full code:
var siteUrl = 'listURL';
var listName = 'listName';
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(listName);
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() +
'nTitre: ' + oListItem.get_item('Titre') +
'nCorps: ' + oListItem.get_item('Corps') +
'nLangue: ' + oListItem.get_item('Langue');
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + 'n' + args.get_stackTrace());
}