Created
November 23, 2013 17:18
-
-
Save bradorego/7617364 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
function sendAJAX(url, method, callback, data, headers) { | |
var xhReq = new XMLHttpRequest(); | |
if (method !== "POST" && method !== "GET" && method !== "PUT" && method !== "DELETE") { | |
return false; | |
} | |
xhReq.open(method, url); | |
if (typeof(headers) != "undefined") { | |
for (var i = 0; i < headers.headers.length; i++) { | |
xhReq.setRequestHeader(headers.headers[i].type, headers.headers[i].value); | |
} | |
} | |
xhReq.onreadystatechange = function () { | |
if (xhReq.readyState != 4) return; | |
callback(xhReq); | |
}; | |
if (xhReq.readyState === 4 ) return xhReq; | |
xhReq.send(data); | |
} | |
var $photoDialog = document.getElementById('photoDialog'); | |
$photoDialog.getElementsByClassName('submit')[0].addEventListener(touchEvent, function (e) { | |
var url = "/" + planIdea + "/" + planIdeaID + "/images", | |
formData = new FormData(), | |
data = {}; | |
formData.append('file', fileObj); | |
formData.append('text', $photoDialog.getElementsByTagName('textarea')[0].value); | |
sendAJAX(url, "POST", function (resp) { | |
if (resp.status === 200) { | |
alert("Image added!"); | |
window.location.reload(); | |
} else { | |
alert("An error occurred. HTTP error " + resp.responseText) | |
} | |
}, formData); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment