replace jquery load with fetch (#828)
* initial implementation * working with Dancer is_ajax * better network errors
This commit is contained in:
@@ -30,21 +30,25 @@ function do_search (event, tab) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// submit the query and put results into the tab pane
|
// submit the query and put results into the tab pane
|
||||||
$(target).load( uri_base + '/ajax/content/' + path + '/' + tab + '?' + query,
|
fetch( uri_base + '/ajax/content/' + path + '/' + tab + '?' + query,
|
||||||
function(response, status, xhr) {
|
{ headers: { 'X-Requested-With': 'XMLHttpRequest' } })
|
||||||
if (status !== "success") {
|
.then( response => {
|
||||||
|
if (! response.ok) {
|
||||||
$(target).html(
|
$(target).html(
|
||||||
'<div class="span5 alert alert-error"><i class="icon-warning-sign"></i> ' +
|
'<div class="span5 alert alert-error"><i class="icon-warning-sign"></i> ' +
|
||||||
'Search failed! Please contact your site administrator.</div>'
|
'Search failed! Please contact your site administrator (server error).</div>'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
// throw new Error('Network response was not ok');
|
||||||
}
|
}
|
||||||
if (response == "") {
|
return response.text();
|
||||||
$(target).html(
|
})
|
||||||
'<div class="span2 alert alert-info">No matching records.</div>'
|
.then( content => {
|
||||||
);
|
if (content == "") {
|
||||||
|
$(target).html('<div class="span2 alert alert-info">No matching records.</div>');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$(target).html(content);
|
||||||
// delegate to any [device|search] specific JS code
|
// delegate to any [device|search] specific JS code
|
||||||
$('div.content > div.tab-content table.nd_floatinghead').floatThead({
|
$('div.content > div.tab-content table.nd_floatinghead').floatThead({
|
||||||
scrollingTop: 40
|
scrollingTop: 40
|
||||||
@@ -52,7 +56,38 @@ function do_search (event, tab) {
|
|||||||
});
|
});
|
||||||
inner_view_processing(tab);
|
inner_view_processing(tab);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch( error => {
|
||||||
|
$(target).html(
|
||||||
|
'<div class="span5 alert alert-error"><i class="icon-warning-sign"></i> ' +
|
||||||
|
'Search failed! Please contact your site administrator (network error: ' + error + ').</div>'
|
||||||
);
|
);
|
||||||
|
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(
|
||||||
|
// '<div class="span5 alert alert-error"><i class="icon-warning-sign"></i> ' +
|
||||||
|
// 'Search failed! Please contact your site administrator.</div>'
|
||||||
|
// );
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// if (response == "") {
|
||||||
|
// $(target).html(
|
||||||
|
// '<div class="span2 alert alert-info">No matching records.</div>'
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 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
|
// keep track of which tabs have a sidebar, for when switching tab
|
||||||
|
|||||||
Reference in New Issue
Block a user