Skip to content

Instantly share code, notes, and snippets.

@xyqfer
Created September 28, 2013 12:02
Show Gist options
  • Save xyqfer/6741381 to your computer and use it in GitHub Desktop.
Save xyqfer/6741381 to your computer and use it in GitHub Desktop.
ajax
$._getConnector = function() {
if ($._support.w3cXMLHTTP) {
return new XMLHttpRequest();
} else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
};
$._configureConnector = function(connector, callback) {
connector.onreadystatechange = function() {
if (connector.readyState === 4) {
if (connector.status === 200) {
callback.call(connector, {
text: connector.responseText,
xml: connector.responseXML
});
}
}
};
};
$.get = function(request) {
var url = request.url,
callback = request.callback,
connector = $._getConnector();
$._configureConnector(connector, callback);
connector.open("get", url, true);
connector.send(null);
};
$.post = function(request) {
var url = request.url,
callback = request.callback,
data = request.data,
connector = $._getConnector();
$._configureConnector(connector, callback);
connector.open("post", url, true);
connector.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
connector.send(data);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment