Skip to content

@mosluce /gist:4993820
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
function parseQuery(json) {
var q = "";
var first = true;
for (var key in json) {
if(json[key]=="" || json[key]==null) continue;
if (first) {
first = false;
q += (key + "=" + json[key]);
} else {
q += ("&" + key + "=" + json[key]);
}
}
return q;
}
function httpRequest(method, url, data) {
var xhr = new XMLHttpRequest();
//ready
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status == 201) {
var responseText = xhr.responseText;
var responseObj = JSON.parse(responseText);
//refresh model
clear();
insertList(responseObj.data);
requestFinished(responseObj.success, method, responseObj.data);
} else {
requestFinished(false, method, "request failed (" + xhr.statusText + ")");
}
}
}
//open
console.log(url);
xhr.open(method, url);
//send
if (data) {
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(parseQuery(data))
} else {
xhr.send();
}
}
httpRequest("PUT", "https://xxx.xxx.com", {"done":1});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.