1

I'm just starting: (1)to code (2)for SP (3)with javascript(3) ... and my first choice was a JSOM. Once i've been trying hard to get a value from executeQueryAsync call and set it to local/global variable with promises, deferreds and so on, but without any success. Among all problems there was also my failures with making code work in order i need to get values. Dissynchronization in other words. So i switched to REST and now my average code looks like:

    var listTitle; 
    var itemName;
    var itemId;
    var fileName; 

    $.when(getListName()).then(getItemName()).then(other_function())......done();

    function getListName() { 
    //local variables here 
    $.ajax({
        url: siteUrl + '/_api/web/lists(guid' + listId + ')',
        async: false,
        type: 'GET',
        headers: { 'accept': 'application/json;odata=verbose' },
        success: function (responseData) {
            var a = somehow_get_listTitle_from_response(); 
            listTitle = a;

        },
        error: errorHandler
    });
    function getItemName() { 
    // almost the same code with async: false
    itemName = somehow_get_itemName_from_response()

}
   // other funcntions like two above;
}

Well, for now it works, but i'm very curious, is that continuous using of async:false a..."good" style to write SP web parts, custom application pages, custom action and so on? Or smart guys do this stuff somehow else in common?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.