Domanda

I have some JSOM code in my master page(seattle.master). The code runs until load() method on the context object but executeQueryAsync is not executing.

    SP.SOD.executeOrDelayUntilScriptLoaded(function(){

                        var context = SP.ClientContext.get_current();   
                        var web = context.get_web();            
                        var list = web.get_lists().getByTitle(list_title);
                        context.load(list);
                        context.executeQueryAsync(function(data){
                        console.log(data);
                        },
                          function(data,args){
                            console.log(args);
                        });
},'sp.js');             

Neither of the log statements in the success nor the error function is getting printed.

Thanks!

È stato utile?

Soluzione

Use your code like below:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
    var context = SP.ClientContext.get_current();   
    var web = context.get_web();            
    var list = web.get_lists().getByTitle(list_title);
    context.load(list);
    context.executeQueryAsync(function(data){
    console.log(data);
    },
      function(data,args){
        console.log(args);
    });
});

Altri suggerimenti

executeQueryAsync requires both succeededCallback and failedCallback parameters per SP.ClientContext.executeQueryAsync method (sp.js). I think you are missing the failedCallback.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top