var ProfileView = View.extend({ el: ".profilepage", events: { "change #profile_avatar": "uploadAvatar", }, initialize: function() { }, load: function() { var classes = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen']; $(".bio").addClass(choice(classes)); this.projectList = new ProjectList () }, uploadAvatar: function(){ var fd = new FormData(), hasCSRF = false var files = this.$("#profile_avatar")[0].files if (! files.length) return fd.append("avatar", files[0]); fd.append("_csrf", $("[name=_csrf]").val()) var request = $.ajax({ url: "/api/profile", type: "put", data: fd, dataType: "json", processData: false, contentType: false, }) request.done($.proxy(function (response) { window.location.href = "/profile" }, this)); } })