JavaScript is not working in MDS enabled site. RRS feed

  • Question

  • I ran into problem when working in MDS mode.

    When running in MDS mode all variables declared as object initializers are undefined!

    FYI, I added all JS files as Custom Actions.

    The variable that I want to use is declared as:

    var ProjectImplementation = {
    callBack: {},
    initSettings: function () { … },
    saveSettings: function(callback) { … }

    Now if I want to call ‘ProjectImplementation.initSettings()’ in MDS mode then ProjectImplementation is undefined.

    However if I use Constructor Function then it works after initialize it again if undefined.

    I also used “RegisterModuleInit” in top of the JS file like below:

    RegisterModuleInit(“/SPFiles/js/SP/SPCommon.js”, ProjectImplementation.initSettings);

    But it states error like “ProjectImplementation” is undefined.

    If I call simple function like:

    RegisterModuleInit(“/SPFiles/js/SP/SPCommon.js”, TestFunc);

    function TestFunc() { alert(‘hello’); }

    It works every time and show me alert!

    Please suggest


    Shahnawaz Khan

    Wednesday, June 25, 2014 2:31 PM


  • hi

    add trace information before and after declaration of ProjectImplementation object:


    var ProjectImplementation = { callBack: {}, initSettings: function () {...}, saveSettings: function(callback) {...} }; console.log("after");

    And see in browser console will the be called or not. If only "before" will be shown, there may be some syntax errors in the ProjectImplementation code.

    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

    • Marked as answer by Dennis Guo Monday, July 7, 2014 1:59 AM
    Wednesday, June 25, 2014 2:56 PM