jquery - Backbone model change event not firing after setting model -
i took non kosher approach , used $.ajax()
ajax file upload because @ moment can't figure out "backbone" way. picture has been uploaded , ajax request sends new backbone model in json, populated filename of new photo. model not firing change
event can't populate profile picture. see success
function below.
getfile:function(e){ e.preventdefault(); = this; var file = e.target.files[0]; name = file.name; size = file.size; type = file.type; var formdata = new formdata($('#upload-child-pic-form')[0]); console.log(this,'currentuploadu',this.currentupload); formdata.append('child_id',this.currentupload); $.ajax({ url: '/children/upload/', type: 'post', xhr: function() { var myxhr = $.ajaxsettings.xhr(); if(myxhr.upload){ myxhr.upload.addeventlistener('progress',function(data){ $("#upload-child-pic-progress").val(data.position / data.totalsize * 100); }, false); } return myxhr; }, //ajax events beforesend: function(data){ $("#upload-child-pic-progress").removeclass('hide'); }, success: function(data){ $("#upload-child-pic-progress").addclass('hide'); $("#add-child-profile-pics-modal").modal('hide'); var sentdata = $.parsejson(data); var thischild = that.children.get(sentdata.id); thischild.set("photo",sentdata.photo); thischild.trigger('change'); }, error: function(data){ console.log('error',data); }, // form data data: formdata, //options tell jquery not process data or worry content-type. cache: false, contenttype: false, processdata: false }); },
you missing var before variables , other variables...
having these variable global menace, can changed/overwritten outside of scope before success callback called.
that = this; //should - 'var = this;'
Comments
Post a Comment