net.put => net.request('PUT'; improved usability for "Save" buttons

This commit is contained in:
Matthias S. Benkmann 2014-12-23 16:33:56 +01:00
commit eccc98b83b
4 changed files with 28 additions and 31 deletions

View file

@ -9,22 +9,9 @@ define(function(require, exports, module) {
"use strict";
var dom = require("./dom");
exports.get = function (url, callback) {
exports.request = function (verb, url, data, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
if (xhr.readyState === 4) {
callback(xhr.responseText);
}
};
xhr.send(null);
};
exports.put = function (url, data, callback) {
var xhr = new XMLHttpRequest();
xhr.open('PUT', url, true);
xhr.open(verb, url, true);
xhr.onreadystatechange = function () {
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
@ -35,6 +22,10 @@ exports.put = function (url, data, callback) {
xhr.send(data);
};
exports.get = function (url, callback) {
this.request('GET', url, null, callback);
};
exports.loadScript = function(path, callback) {
var head = dom.getDocumentHead();
var s = document.createElement('script');