@LioneNET

Как отправить запрос ajax в backbonejs?

Привет всем
Подскажите как можно отправить запрос ajax, а потом пришедшие данные загрузить в backbone?

Делаю так:

....
....

var CatsVew = Backbone.View.extend({
        el: ".all_cats_content",
        initialize: function (initLinks) {
            this.collection = new LinksCollection(initLinks);
            this.render();
        },
        render: function () {
            this.collection.each(function (item) {
                this.renderLink(item);
            }, this);
        },
        renderLink: function (item) {
            var linkVew = new LinkVew({
                model: item
            });
            this.$el.prepend(linkVew.render().el);
        }
    });


$.ajax({
        type: 'POST',
        url: 'mainpage/init',
        data: {protect:$('#_mfk').val()},
        success: function (data) {
            if (IsJsonString(data) !== false) {
                data = JSON.parse(data);
                new PathVew(data['msg'].itemsPath);
                new CatsVew(data['msg'].itemsCats);
                new MenuView();
            } else
                console.log(data);
        },
        complete: function () {
            $('.parent_load_block1').hide();
        },
        error: function (xhr, str) {
            alert('Возникла ошибка: ' + xhr.responseCode);
        }
    });


Некатит...
  • Вопрос задан
  • 191 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы