1

I'm sure I'm missing some file but this script work when page is in edit mode but not when it is in display mode?

<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");

function retrieveListItems() {

    var clientContext = new SP.ClientContext('/News');

    var oList = clientContext.get_web().get_lists().getByTitle('Posts');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<View><Query><Where><Geq><FieldRef Name='PublishedDate' /><Value Type='DateTime'><Today /></Value></Geq></Where></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='NumComments' /><FieldRef Name='PublishedDate' /><FieldRef Name='SNAP_x0020_Summary' /><FieldRef Name='_x0023_Likes' /></ViewFields></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();

        var title = oListItem.get_item('Title');

        $("#pageContent").append(title +"<br/>");
    }
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • Is this site using minimal download strategy? – Eric Alexander Jun 12 '15 at 16:01
  • Well we started with a minimal master page but same MP used on other pages and ECMA is working fine. – RkH Jun 12 '15 at 16:03
  • I mean are you specifically using the Minimal Download Strategy feature on the site? – Eric Alexander Jun 12 '15 at 16:05
  • Sorry.. .No we are not. This is a blog site .. that is the only difference form our other pages. – RkH Jun 12 '15 at 16:08
3

Use SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems); instead of ExecuteOrDelayUntilScriptLoaded . This will make sure that sp.js is loaded , if it is not already loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.