Created
May 24, 2016 04:22
-
-
Save JamsMendez/ff425d845f9784e92fc4191018924094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addJSON (json) { | |
let self = this; | |
let formData = new FormData(); | |
formData.append('json', JSON.stringify(json)); | |
formData.append('file', avatar); | |
let xhr = $.ajax({ | |
url: 'URL', | |
method: 'METHOD', | |
processData: false, | |
contentType: false, | |
data: formData, | |
}); | |
xhr.done((res, status, response) => { | |
if (response.status == constants.OK_REQ) { | |
let message = 'Los datos se guardaron correctamente'; | |
self.onMessage(message); | |
} else if (response.status == constants.ACCEPTED_REQ) { | |
self.onMessage(res.message); | |
} | |
}); | |
xhr.fail((res, status, respose) => { | |
if (res.responseJSON) { | |
let json = res.responseJSON; | |
self.onMessage(json.message); | |
} else { | |
self.onMessage(constants.MESSAGE_ERROR); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment