PageSourceSearch

https://goessner.net/js/http.js

js goessner.net collected 2026-10-01 07:26:35 UTC 3,523 bytes, 103 lines download raw bytes

1/*	This work is licensed under Creative Commons GNU LGPL License.
2
3	License: http://creativecommons.org/licenses/LGPL/2.1/
4
5   Version: 1.0
6
7	Author:  Stefan Goessner/2004-06
8	Web:     http://goessner.net/ 
9*/
10var Http = {
11   get: function(uri, callback, onrequest, onresponse) {
12      try {
13         var http = Http.createInstance();
14         http.onreadystatechange = function() {
15            if (http.readyState == 4 && http.status == 200 && callback) {
16               callback(http.responseText);
17               if (onresponse) onresponse();
18            }
19            return true;
20         };
21         if (onrequest) onrequest();
22         http.open("GET", uri, true);
23         http.send(null);
24      }
25      catch(e) {
26         window.alert("Http.get: " + e.toString());
27      }
28      return false;
29   },
30   post: function(string, uri, callback, onrequest, onresponse) {
31      try {
32         var http = Http.createInstance();
33         http.onreadystatechange = function() {
34            if (http.readyState == 4 && http.status == 200 && callback) {
35               callback(http.responseText);
36               if (onresponse) onresponse();
37            }
38         };
39         if (onrequest) onrequest();
40         http.open("POST", uri, true);
41         http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); // for php variable $_post to work ..
42         http.setRequestHeader("Content-Length", string.length);
43         http.setRequestHeader("Connection", "close");
44         http.send(string);
45      }
46      catch(e) {
47         window.alert("Http.post: " + e.toString());
48      }
49      return false;
50   },
51   put: function(string, uri, callback) {
52      try {
53         var http = Http.createInstance();
54         http.onreadystatechange = function() {
55            if (http.readyState == 4 && http.status == 200 && callback)
56               callback(http.responseText);
57         };
58         http.open("PUT", uri, true);
59         http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); // for php variable $_post to work ..
60         http.setRequestHeader("Content-Length", string.length);
61         http.send(string);
62      }
63      catch(e) {
64         window.alert("Http.put: " + e.toString());
65      }
66      return false;
67   },
68   del: function(uri, callback) {
69      try {
70         var http = Http.createInstance();
71         http.onreadystatechange = function() {
72            if (http.readyState == 4 && http.status == 200 && callback)
73               callback(http.responseText);
74         };
75         http.open("DELETE", uri, true);
76         http.send(null);
77      }
78      catch(e) {
79         window.alert("Http.delete: " + e.toString());
80      }
81      return false;
82   },
83   createInstance: function() {
84      var o = null;
85      if (!!window.XMLHttpRequest) {
86         try { o = new XMLHttpRequest(); } catch (e) { o = null; }
87      }
88      else if (!!window.ActiveXObject) {
89         try {o = new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch (e) { 
90            try {o = new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) { 
91               try {o = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { 
92                  try { o = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { 
93                     try { o = new ActiveXObject("MSXML.XMLHTTP"); } catch (e) { 
94                        try { o = new ActiveXObject("MSXML3.XMLHTTP"); } catch (e) { o = null; }
95                     }
96                  }
97               }
98            }
99         }
100      }
101      return o;
102   }
103};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.