1

$.ajax()現時点では「バックボーン」の方法がわかりません。写真がアップロードされ、ajax リクエストによって、新しい写真のファイル名が取り込まれた新しいバックボーン モデルが JSON で返されます。ただし、モデルはchangeイベントを発生させていないため、プロフィール写真を入力できません。success以下の関数を参照してください。

    getFile:function(e){
        e.preventDefault();
        that = 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 to tell jQuery not to process data or worry about content-type.
            cache: false,
            contentType: false,
            processData: false
        });
    },
4

1 に答える 1