Created
May 26, 2011 07:16
-
-
Save mapserver2007/992700 to your computer and use it in GitHub Desktop.
mix.js用HTTPモジュール(要jQuery)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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