0

I am using this code:

"use strict"
var BasicJSOM = window.BasicJSOM || {};
BasicJSOM.Crud = BasicJSOM.Crud || {};

$(function() {
   BasicJSOM.Crud.MainDemo = new BasicJSOM.Crud.Main();
SP.SOD.executeOrDelayUntilScriptLoaded(BasicJSOM.Crud.MainDemo.readListItems("pages"), "SP.js");   
  });


 BasicJSOM.Crud.Main= function(){

    function _readListItems(library){

       var context = SP.ClientContext.get_current();
       var targetList = context.get_web().get_lists().getByTitle(library);
       var query = new SP.CamelQuery();
        var listItems = targetList.getItems();

        results = context.loadQuery(listItems);
        context.executeQueryAsync(_onSucceed, _Fail);

       function _onSucceed(){
            alert("Success"); 

       }

       function _Fail(){
       alert("fail"); 
       }

    }//end of read list


    return {
readListItems: _readListItems    
    }

 } 

But the error am having is about the SP.js is not loaded, I am using jQuery to wait for page load, then using SP.SOD.executeOrDelayUntilScriptLoaded. What else am I missing?

3

You should specify a function as the first parameter of the executeOrDelayUntilScriptLoaded method, like BasicJSOM.Crud.MainDemo.readListItems. If you use BasicJSOM.Crud.MainDemo.readListItems("pages"), the function is executed immediately, that means probably before the SP.js library loaded.

If you need to pass a parameter to the method, use the following syntax:

SP.SOD.executeOrDelayUntilScriptLoaded(function () { BasicJSOM.Crud.MainDemo.readListItems("pages") }, "SP.js");   

See this question as reference.

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.