add Ox.post(like Ox.get)

This commit is contained in:
j 2015-03-14 11:25:45 +05:30
parent 97ede3643e
commit a4451b5dd8

View file

@ -289,3 +289,32 @@ Ox.getJSONP = function(url, callback) {
}));
}, callback);
};
/*@
Ox.post <f> post to a remote resource
(url, data, callback) -> <u> undefined
url <s> Remote URL
data <s> data to send in post request
callback <f> Callback function
data <s|null> The contents of the remote resource, or `null` on error
error <o|null> Error, or `null` on success
code <n> Status code
text <s> 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);
};