Показать сообщение отдельно
  #2 (permalink)  
Старый 17.02.2017, 01:08
Аватар для Alexandroppolus
Профессор
Отправить личное сообщение для Alexandroppolus Посмотреть профиль Найти все сообщения от Alexandroppolus
 
Регистрация: 25.10.2016
Сообщений: 1,005

var menu_js = {
        url:"js/menu.json",
        json_data: 'empty',
        menu: '',
        init:function(){

            this.load_json(function( jsonData ) {
                this.json_data = jsonData;

                this.draw_menu(); //отрисовка меню
            });
        },
        load_json: function(ready){
            var self = this;
            var xhr = new XMLHttpRequest();
            xhr.open( 'GET', this.url, true );
            xhr.send();
            xhr.onreadystatechange = function() {
                if (xhr.readyState != 4) return;
                if (xhr.status != 200) {
                    console.log(xhr.status + ': ' + xhr.statusText);
                } else {
                   ready.call(self, JSON.parse(xhr.responseText));
                }
            }
        },
        draw_menu: function(){
            // здесь уже получена this.json_data
        }
}
Ответить с цитированием