3 Ajax.prototype.jsonpHandler = function(url, callback) {
4 var scripturl = url + ((url.indexOf("?") !== -1) ? "&" : "?") + "callback=" + callback;
5 document.write('<script src="' + scripturl + '"></script>');
9 Ajax.prototype.request = function(method, url, fallback, options) {
11 options = options || {},
14 params = options.params;
16 return self.jsonpHandler(url, options.jsonpCallback);
18 var xhr = new XMLHttpRequest();
19 if ("withCredentials" in xhr) {
20 xhr.open(method, url, true);
21 } else if (typeof XDomainRequest !== "undefined") {
22 xhr = new XDomainRequest();
23 xhr.open(method, url);
25 if (fallback === true) {
26 xhr.open(method, url, true);
32 xhr.onreadystatechange = function(event) {
33 if (this.readyState === 4) {
34 if (this.status === 200 && sf) {
35 sf(this.responseText);
37 ef("Not OK. " + this.statusText);
41 xhr.onerror = function(data) {
43 ef("ajax error " + this.statusText);
47 xhr.withCredentials = true;
48 xhr.setRequestHeader("Authorization", 'Basic ' + btoa('admin:password'));
50 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
57 ef("error " + e.name + ": " + e.message);