L
L
LyoneNET2016-07-11 22:29:17
backbone.js
LyoneNET, 2016-07-11 22:29:17

How to send an ajax request in backbonejs?

Hello everyone
Tell me how you can send an ajax request, and then upload the incoming data to the backbone?

I do it like this:

....
....

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);
        }
    });


Not okay...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question