The following code fixed it:
self.uploadImage = function (file) {
/* Is the file an image? */
if (!file || !file.type.match(/image.*/)) return;
/* It is! */
document.body.className = "uploading";
/* Lets build a FormData object*/
var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
fd.append("image", file); // Append the file
var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
xhr.open("POST", "https://api.imgur.com/3/image.json"); // Boooom!
xhr.onload = function () {
var response1 = JSON.parse(xhr.responseText);
var response = JSON.parse(xhr.responseText).data.link;
document.querySelector("#image-uploaded-one-" + self.cardId()).href = response;
}
// Ok, I don't handle the errors. An exercice for the reader.
xhr.setRequestHeader('Authorization', 'Client-ID <yourkey>');
/* And now, we send the formdata */
xhr.send(fd);
};