Backbone.js the file field in the model

Kind time of days, prompt how to use backbone.js model uploading files to the server?
October 8th 19 at 00:25
2 answers
October 8th 19 at 00:27
October 8th 19 at 00:29
Not to pull out a piece of the project with github will give an example here.
Model in CoffeeScript looks like this:
class document.model_prototypes.TmpIconModel extends Backbone.Model
 urlRoot: "/admin/tmp_icon"
methodMap:
 'create': 'POST'
 'update': 'PUT'
 'delete': 'DELETE'
 'read': 'GET'
 sync:(method, model, options)->
 type = this.methodMap[method]
self=this
 if type == 'DELETE' or type =='GET' 
 return Backbone.sync(method, model, options)
else
 form=new FormData()
form.append('temporary_term_icon[image]',this.attributes.image)
 url = this.url()
 if options.url
 url = options.url
 xhr = new XMLHttpRequest()
 xhr.onreadystatechange = 
()->
 if xhr.readyState == 4
 if xhr.status== 200 or xhr.status == 201
options.success($.parseJSON(xhr.response),xhr.status,xhr)
else
options.error(self,$.parseJSON(xhr.response))
 xhr.open(type, url)
 xhr.setRequestHeader('Accept', 'application/json')
xhr.send(form)

Find more questions by tags Backbone.jsAJAXJavaScript