Skip to content

Business intelligence made simple

Switched to fetch for some requests [skip ci]

Andrew Kane508365dfe30c
diff --git a/app/assets/javascripts/blazer/application.js b/app/assets/javascripts/blazer/application.js
index b38b89fe..1e544d16 100644
--- a/app/assets/javascripts/blazer/application.js
+++ b/app/assets/javascripts/blazer/application.js
@@ -114,3 +114,14 @@ function toggle(element, found) {
hide(element)
}
}
+
+function getJSON(url, success) {
+ fetch(url, {headers: {"Accept": "application/json"}})
+ .then(function (response) {
+ if (!response.ok) {
+ throw new Error("Bad response")
+ }
+ return response.json()
+ })
+ .then(success)
+}
diff --git a/app/views/blazer/queries/_form.html.erb b/app/views/blazer/queries/_form.html.erb
index e84625b0..57a6118a 100644
--- a/app/views/blazer/queries/_form.html.erb
+++ b/app/views/blazer/queries/_form.html.erb
@@ -140,7 +140,7 @@
tablesXhr.abort()
}
- tablesXhr = $.getJSON(Routes.tables_queries_path({data_source: dataSource}), function (data) {
+ tablesXhr = getJSON(Routes.tables_queries_path({data_source: dataSource}), function (data) {
const newOptions = []
for (const table of data) {
if (typeof table === "object") {
diff --git a/app/views/blazer/queries/home.html.erb b/app/views/blazer/queries/home.html.erb
index 25fed7e7..0b5d9158 100644
--- a/app/views/blazer/queries/home.html.erb
+++ b/app/views/blazer/queries/home.html.erb
@@ -143,7 +143,7 @@
if (more) {
show(loading)
- $.getJSON(Routes.queries_path(), function (queries) {
+ getJSON(Routes.queries_path(), function (queries) {
hide(loading)
const newItems = []