Skip to content

Instantly share code, notes, and snippets.

@nakamura-to
Created October 31, 2012 11:36
Show Gist options
  • Save nakamura-to/3986585 to your computer and use it in GitHub Desktop.
Save nakamura-to/3986585 to your computer and use it in GitHub Desktop.
Concept code of WinJS.xhr Wrapper
var xhr = new Xhr({
baseUrl: 'http://localhost:8080/api',
user: "",
password: "",
type: 'json',
preHandler: function () {},
postHandler: function () {},
errorHandler, function () {}
headers: {},
data: {},
acceptStatus: [200]
});
function getAaa(code) {
return xhr.get({ url: '/aaa/bbb', data: {code: code}, headers: {}, acceptStatus: [] }).then(Xhr.toJSON);
}
function deleteBbb(id) {
return xhr.del({ url: '/aaa/bbb', data: {id: id}, headers: {}, acceptStatus: [] }).then(Xhr.toJSON);
}
function Xhr(options) {
...
}
Xhr.toJSON = function (result) {
return JSON.parse(result.response);
}
Xhr.prototype.get = function (options) {
...
}
Xhr.prototype.post = function (options) {
...
}
Xhr.prototype.put = function (options) {
...
}
Xhr.prototype.del = function (options) {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment