From 29de4465f9b992fcfc765df69dca1d6f0c8fa652 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 12 Oct 2021 13:09:18 +0100 Subject: [PATCH] replace jquery load with fetch (#828) --- .gitattributes | 1 + share/public/javascripts/netdisco.js | 24 ------------------------ share/views/index.tt | 23 ++++++++++++++++++----- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/.gitattributes b/.gitattributes index f2ecb34e..2e516c40 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,5 @@ share/public/javascripts/*.map binary share/public/javascripts/*.min.js binary +share/public/javascripts/jquery-history.js binary share/public/css/*.min.css binary share/public/swagger-ui/* binary diff --git a/share/public/javascripts/netdisco.js b/share/public/javascripts/netdisco.js index 6018997b..f270ecf0 100644 --- a/share/public/javascripts/netdisco.js +++ b/share/public/javascripts/netdisco.js @@ -64,30 +64,6 @@ function do_search (event, tab) { ); console.error('There has been a problem with your fetch operation:', error); }); - -// $(target).load( uri_base + '/ajax/content/' + path + '/' + tab + '?' + query, -// function(response, status, xhr) { -// if (status !== "success") { -// $(target).html( -// '
' + -// 'Search failed! Please contact your site administrator.
' -// ); -// return; -// } -// if (response == "") { -// $(target).html( -// '
No matching records.
' -// ); -// } -// -// // delegate to any [device|search] specific JS code -// $('div.content > div.tab-content table.nd_floatinghead').floatThead({ -// scrollingTop: 40 -// ,useAbsolutePositioning: false -// }); -// inner_view_processing(tab); -// } -// ); } // keep track of which tabs have a sidebar, for when switching tab diff --git a/share/views/index.tt b/share/views/index.tt index 74d29b27..0b9155cc 100644 --- a/share/views/index.tt +++ b/share/views/index.tt @@ -113,12 +113,25 @@ $('.nd_chevron').toggleClass('icon-chevron-up icon-chevron-down'); if (! stats_loaded) { - $('#nd_stats').load("[% uri_for('/ajax/content/statistics') | none %]", function(r,s,x) { - if (s == "error") { + fetch( "[% uri_for('/ajax/content/statistics') | none %]", + { headers: { 'X-Requested-With': 'XMLHttpRequest' } }) + .then( response => { + if (! response.ok) { + $('#nd_stats_status').addClass('alert-error') + .html(' Failed to retrieve system information (server error).'); + return; + // throw new Error('Network response was not ok'); + } + return response.text(); + }) + .then( content => { + $('#nd_stats').html(content); + }) + .catch( error => { $('#nd_stats_status').addClass('alert-error') - .html(' Failed to retrieve system information.'); - } - }); + .html(' Failed to retrieve system information (network error: ' + error + ').'); + console.error('There has been a problem with your fetch operation:', error); + }); stats_loaded = 1; } });