Changeset 38427 for main/trunk/greenstone3/web
- Timestamp:
- 2023-11-23T20:19:49+13:00 (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r38257 r38427 5 5 var COMPLETED = 11; 6 6 var HALTED = 12; 7 8 var runningAjaxCalls = []; 7 9 8 10 gs.functions = {}; … … 548 550 // ajax calls default to using method GET, we want to do POST operations for get-meta and set-meta requests 549 551 // since get-meta-array and especially set-meta-array can be large, e.g. for user comments. 550 $.ajax({url: url, async: async_setting, type: method, data: data})552 var ajaxCall = $.ajax({url: url, async: async_setting, type: method, data: data}) 551 553 .done(function(response) { 552 554 ajaxResponse = response; … … 561 563 if(response.indexOf("ERROR: ") !== -1 || response.indexOf("<Error>") !== -1) { 562 564 if(errorResponseFunction != null) { 563 console.log(" (" + callingFunction + ") Failed with gsdlcgi error:\n" + response);565 console.log("!!!! (" + callingFunction + ") Failed with gsdlcgi error:\n" + response); 564 566 errorResponseFunction(response); 565 567 } else { 566 alert("(" + callingFunction + ") Failed\n" + response); 567 console.log("(" + callingFunction + ") Failed\n" + response); 568 } 569 568 alert("@@@ (" + callingFunction + ") Failed\n" + response); 569 console.log("@@@ (" + callingFunction + ") Failed\n" + response); 570 } 570 571 } 571 572 … … 575 576 } 576 577 }) 577 .fail(function(response) { 578 .fail(function(response, textStatus, errorThrown) { 579 // https://stackoverflow.com/questions/13258784/stopping-an-ajax-call-on-page-unload 580 // https://api.jquery.com/jQuery.ajax/ 581 if(textStatus == "abort") { 582 console.log ("INFO: Navigating away from page, so aborted running ajax."); 583 } else { 584 578 585 if(errorResponseFunction != null) { 579 console.log(" (" + callingFunction + ") Failed\n" + response);586 console.log("*** (" + callingFunction + ") Failed\n" + response); 580 587 errorResponseFunction(response); 581 588 } else { 582 589 alert("(" + callingFunction + ") Failed\n" + response); 583 console.log(" (" + callingFunction + ") Failed\n" + response);590 console.log("*** (" + callingFunction + ") Failed\n" + response); 584 591 } 592 } 593 }) 594 .always(function(data) { // https://api.jquery.com/jQuery.ajax/ 595 596 // this call has terminated one way or another, remove it from the list we maintain 597 // of runningAjaxCalls 598 var index_of_call = runningAjaxCalls.indexOf(ajaxCall); 599 if(index_of_call != -1) { 600 // null this ajaxCall in the runningAjaxCalls array if not already nulled 601 //runningAjaxCalls[index_of_call] = null; 602 603 // remove this 1 call from the runningAjaxCalls array 604 runningAjaxCalls.splice(index_of_call, 1); 605 } 606 585 607 }); 608 609 // now we've launched an ajax call, let's add it to our list of runningAjaxCalls 610 runningAjaxCalls.push(ajaxCall); 586 611 } 587 612 else { … … 1120 1145 } 1121 1146 } 1147 1148 // When user prematurely navigates away from current page before the page has finished all 1149 // running ajax calls, abort those still running. Else the error callback is called 1150 // and error messages are displayed. 1151 // https://stackoverflow.com/questions/13258784/stopping-an-ajax-call-on-page-unload 1152 // See also gs.functions._callMetadataServer() which maintains the array of running ajax calls 1153 // and removes finished calls from the runningAjaxCalls array. 1154 //window.onbeforeunload = function(event) { 1155 $(window).on("beforeunload", function(event) { 1156 var i = 0; 1157 var ajaxCall; 1158 for (i = 0; i < runningAjaxCalls.length; i++) { // list of only *running* ajax calls 1159 ajaxCall = runningAjaxCalls[i]; 1160 // abort each still running ajaxCall (gets removed from runningAjaxCalls list elsewhere) 1161 ajaxCall.abort(); 1162 } 1163 });
Note:
See TracChangeset
for help on using the changeset viewer.