Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -1,7 +1,3 @@
var req = new XMLHttpRequest();
req.onload = function() {
console.log(this.responseText);
};
req.open('get', 'http://rosettacode.org', true);
req.send()
const response = await fetch('http://rosettacode.org');
const text = await response.text();
console.log(text);

View file

@ -1,5 +1,5 @@
fetch('http://rosettacode.org').then(function(response) {
fetch('http://rosettacode.org').then(function (response) {
return response.text();
}).then(function(myText) {
console.log(myText);
}).then(function (text) {
console.log(text);
});

View file

@ -1,65 +1,7 @@
/**
* @name _http
* @description Generic API Client using XMLHttpRequest
* @param {string} url The URI/URL to connect to
* @param {string} method The HTTP method to invoke- GET, POST, etc
* @param {function} callback Once the HTTP request has completed, responseText is passed into this function for execution
* @param {object} params Query Parameters in a JavaScript Object (Optional)
*
*/
function _http(url, method, callback, params) {
var xhr,
reqUrl;
var req = new XMLHttpRequest();
req.onload = function() {
console.log(this.responseText);
};
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function xhrProc() {
if (xhr.readyState == 4 && xhr.status == 200) {
callback(xhr.responseText);
}
};
/** If Query Parameters are present, handle them... */
if (typeof params === 'undefined') {
reqUrl = url;
} else {
switch (method) {
case 'GET':
reqUrl = url + procQueryParams(params);
break;
case 'POST':
reqUrl = url;
break;
default:
}
}
/** Send the HTTP Request */
if (reqUrl) {
xhr.open(method, reqUrl, true);
xhr.setRequestHeader("Accept", "application/json");
if (method === 'POST') {
xhr.send(params);
} else {
xhr.send();
}
}
/**
* @name procQueryParams
* @description Return function that converts Query Parameters from a JavaScript Object to a proper URL encoded string
* @param {object} params Query Parameters in a JavaScript Object
*
*/
function procQueryParams(params) {
return "?" + Object
.keys(params)
.map(function (key) {
return key + "=" + encodeURIComponent(params[key])
})
.join("&")
}
}
req.open('get', 'http://rosettacode.org', true);
req.send()

View file

@ -1,3 +1,65 @@
$.get('http://rosettacode.org', function(data) {
console.log(data);
};
/**
* @name _http
* @description Generic API Client using XMLHttpRequest
* @param {string} url The URI/URL to connect to
* @param {string} method The HTTP method to invoke- GET, POST, etc
* @param {function} callback Once the HTTP request has completed, responseText is passed into this function for execution
* @param {object} params Query Parameters in a JavaScript Object (Optional)
*
*/
function _http(url, method, callback, params) {
var xhr,
reqUrl;
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function xhrProc() {
if (xhr.readyState == 4 && xhr.status == 200) {
callback(xhr.responseText);
}
};
/** If Query Parameters are present, handle them... */
if (typeof params === 'undefined') {
reqUrl = url;
} else {
switch (method) {
case 'GET':
reqUrl = url + procQueryParams(params);
break;
case 'POST':
reqUrl = url;
break;
default:
}
}
/** Send the HTTP Request */
if (reqUrl) {
xhr.open(method, reqUrl, true);
xhr.setRequestHeader("Accept", "application/json");
if (method === 'POST') {
xhr.send(params);
} else {
xhr.send();
}
}
/**
* @name procQueryParams
* @description Return function that converts Query Parameters from a JavaScript Object to a proper URL encoded string
* @param {object} params Query Parameters in a JavaScript Object
*
*/
function procQueryParams(params) {
return "?" + Object
.keys(params)
.map(function (key) {
return key + "=" + encodeURIComponent(params[key])
})
.join("&")
}
}

View file

@ -1,19 +1,3 @@
const http = require('http');
http.get('http://rosettacode.org', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log("Data:", data);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
$.get('http://rosettacode.org', function(data) {
console.log(data);
};

View file

@ -0,0 +1,19 @@
const http = require('http');
http.get('http://rosettacode.org', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log("Data:", data);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});