Networking
Fetch
CrossBrowdy will support the Fetch API natively or it will fallback back automatically to a polyfill internally, so you do not need to worry at all. Here is an example of Fetch management:
//For modern clients:
CB_Net.Fetch.get("whatever/test_fetch_text.txt").then
(
//Treats the response as text:
function(response) { return response.text(); }
).then
(
//Displays the content received:
function(content) { CB_console("Content received: " + content); }
).catch
(
//Displays the error:
function(error) { CB_console(error); }
);
//For all clients, including legacy ones (to prevent errors because of using "catch" since it is a reserved word):
CB_Net.Fetch.get("whatever/test_fetch_text.txt").then
(
//Treats the response as text:
function(response) { return response.text(); }
).then
(
//Displays the content received:
function(content) { CB_console("Content received: " + content); },
//Displays the error:
function(error) { CB_console(error); }
);
//Another way for all clients, including legacy ones (to prevent errors because of using "catch" since it is a reserved word):
CB_Net.Fetch.get("whatever/test_fetch_text.txt").then
(
//Treats the response as text:
function(response) { return response.text(); }
).then
(
//Displays the content received:
function(content) { CB_console("Content received: " + content); }
)["catch"]
(
//Displays the error:
function(error) { CB_console(error); }
);
Check the API documentation to read more about the CB_Net and the CB_Net.Fetch static classes.