Skip to content

Instantly share code, notes, and snippets.

@mapserver2007
Created May 26, 2011 07:16
Show Gist options
  • Save mapserver2007/992700 to your computer and use it in GitHub Desktop.
Save mapserver2007/992700 to your computer and use it in GitHub Desktop.
mix.js用HTTPモジュール(要jQuery)
var Http = Module.create({
xhr: function(url, params, opts, successCallback, errorCallback, startFunc, endFunc) {
var caller = function(f) {
if (typeof f === "function") {
f.call(this);
}
};
var start = function() { caller(startFunc); },
end = function() { caller(endFunc); },
success = function(callback, response, args) {
end();
if (typeof callback === "function") {
callback.call(this, response, args);
}
else {
throw response;
}
},
error = function(callback, response, args) {
end();
if (typeof callback === "function") {
callback.call(this, response, args);
}
alert(response);
};
start();
$.ajax({
type: opts.type,
dataType: opts.dataType,
data: params,
cache: true,
url: url,
success: function(data, dataType) {
success(successCallback, data, opts.args);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
error(errorCallback, textStatus, opts.args);
}
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment