diff --git a/source/Ox/js/Request.js b/source/Ox/js/Request.js index 58c78d32..193ac66c 100644 --- a/source/Ox/js/Request.js +++ b/source/Ox/js/Request.js @@ -289,3 +289,32 @@ Ox.getJSONP = function(url, callback) { })); }, callback); }; + +/*@ +Ox.post post to a remote resource + (url, data, callback) -> undefined + url Remote URL + data data to send in post request + callback Callback function + data The contents of the remote resource, or `null` on error + error Error, or `null` on success + code Status code + text Status text +@*/ +Ox.post = function(url, data, callback) { + var request = new XMLHttpRequest(); + request.open('post', url, true); + request.onreadystatechange = function() { + if (request.readyState == 4) { + if (request.status == 200) { + callback(request.responseText, null); + } else { + callback(null, { + code: request.status, + text: request.statusText + }); + } + } + }; + request.send(data); +};