includes/clientside/static/ajax.js
changeset 581 5e8fd89c02ea
parent 566 06d241de3151
child 582 a38876c0793c
equal deleted inserted replaced
580:41c45314ac27 581:5e8fd89c02ea
     1 /*
     1 /*
     2  * AJAX applets
     2  * AJAX applets
     3  */
     3  */
     4  
     4  
       
     5 function ajaxMakeXHR()
       
     6 {
       
     7   var ajax;
       
     8   if (window.XMLHttpRequest) {
       
     9     ajax = new XMLHttpRequest();
       
    10   } else {
       
    11     if (window.ActiveXObject) {           
       
    12       ajax = new ActiveXObject("Microsoft.XMLHTTP");
       
    13     } else {
       
    14       alert('Enano client-side runtime error: No AJAX support, unable to continue');
       
    15       return;
       
    16     }
       
    17   }
       
    18   return ajax;
       
    19 }
       
    20 
     5 function ajaxGet(uri, f, call_editor_safe) {
    21 function ajaxGet(uri, f, call_editor_safe) {
     6   // Is the editor open?
    22   // Is the editor open?
     7   if ( editor_open && !call_editor_safe )
    23   if ( editor_open && !call_editor_safe )
     8   {
    24   {
     9     // Make sure the user is willing to close the editor
    25     // Make sure the user is willing to close the editor
    16     }
    32     }
    17     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
    33     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
    18     editor_open = false;
    34     editor_open = false;
    19     enableUnload();
    35     enableUnload();
    20   }
    36   }
    21   if (window.XMLHttpRequest) {
    37   ajax = ajaxMakeXHR();
    22     ajax = new XMLHttpRequest();
    38   if ( !ajax )
    23   } else {
    39   {
    24     if (window.ActiveXObject) {           
    40     console.error('ajaxMakeXHR() failed');
    25       ajax = new ActiveXObject("Microsoft.XMLHTTP");
    41     return false;
    26     } else {
       
    27       alert('Enano client-side runtime error: No AJAX support, unable to continue');
       
    28       return;
       
    29     }
       
    30   }
    42   }
    31   ajax.onreadystatechange = f;
    43   ajax.onreadystatechange = f;
    32   ajax.open('GET', uri, true);
    44   ajax.open('GET', uri, true);
    33   ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
    45   ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
    34   ajax.send(null);
    46   ajax.send(null);
    48     }
    60     }
    49     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
    61     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
    50     editor_open = false;
    62     editor_open = false;
    51     enableUnload();
    63     enableUnload();
    52   }
    64   }
    53   if (window.XMLHttpRequest) {
    65   ajax = ajaxMakeXHR();
    54     ajax = new XMLHttpRequest();
    66   if ( !ajax )
    55   } else {
    67   {
    56     if (window.ActiveXObject) {           
    68     console.error('ajaxMakeXHR() failed');
    57       ajax = new ActiveXObject("Microsoft.XMLHTTP");
    69     return false;
    58     } else {
       
    59       alert('Enano client-side runtime error: No AJAX support, unable to continue');
       
    60       return;
       
    61     }
       
    62   }
    70   }
    63   ajax.onreadystatechange = f;
    71   ajax.onreadystatechange = f;
    64   ajax.open('POST', uri, true);
    72   ajax.open('POST', uri, true);
    65   ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    73   ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    66   // Setting Content-length in Safari triggers a warning
    74   // Setting Content-length in Safari triggers a warning