includes/clientside/static/functions.js
changeset 823 4596c40aaa94
parent 810 7fd2b8a58ae4
child 832 7152ca0a0ce9
equal deleted inserted replaced
822:3b951ea8e758 823:4596c40aaa94
   103     }
   103     }
   104     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
   104     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
   105     editor_open = false;
   105     editor_open = false;
   106     enableUnload();
   106     enableUnload();
   107   }
   107   }
   108   ajax = ajaxMakeXHR();
   108   var ajax = ajaxMakeXHR();
   109   if ( !ajax )
   109   if ( !ajax )
   110   {
   110   {
   111     console.error('ajaxMakeXHR() failed');
   111     console.error('ajaxMakeXHR() failed');
   112     return false;
   112     return false;
   113   }
   113   }
   114   ajax.onreadystatechange = f;
   114   ajax.onreadystatechange = function()
       
   115   {
       
   116     f(ajax);
       
   117   };
   115   ajax.open('GET', uri, true);
   118   ajax.open('GET', uri, true);
   116   ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
   119   ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
   117   ajax.send(null);
   120   ajax.send(null);
       
   121   window.ajax = ajax;
   118 }
   122 }
   119 
   123 
   120 function ajaxPost(uri, parms, f, call_editor_safe) {
   124 function ajaxPost(uri, parms, f, call_editor_safe) {
   121   // Is the editor open?
   125   // Is the editor open?
   122   if ( editor_open && !call_editor_safe )
   126   if ( editor_open && !call_editor_safe )
   131     }
   135     }
   132     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
   136     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
   133     editor_open = false;
   137     editor_open = false;
   134     enableUnload();
   138     enableUnload();
   135   }
   139   }
   136   ajax = ajaxMakeXHR();
   140   var ajax = ajaxMakeXHR();
   137   if ( !ajax )
   141   if ( !ajax )
   138   {
   142   {
   139     console.error('ajaxMakeXHR() failed');
   143     console.error('ajaxMakeXHR() failed');
   140     return false;
   144     return false;
   141   }
   145   }
   142   ajax.onreadystatechange = f;
   146   ajax.onreadystatechange = function()
       
   147   {
       
   148     f(ajax);
       
   149   };
   143   ajax.open('POST', uri, true);
   150   ajax.open('POST', uri, true);
   144   ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   151   ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   145   // Setting Content-length in Safari triggers a warning
   152   // Setting Content-length in Safari triggers a warning
   146   if ( !is_Safari )
   153   if ( !is_Safari )
   147   {
   154   {
   148     ajax.setRequestHeader("Content-length", parms.length);
   155     ajax.setRequestHeader("Content-length", parms.length);
   149   }
   156   }
   150   ajax.setRequestHeader("Connection", "close");
   157   ajax.setRequestHeader("Connection", "close");
   151   ajax.send(parms);
   158   ajax.send(parms);
       
   159   window.ajax = ajax;
   152 }
   160 }
   153 
   161 
   154 /**
   162 /**
   155  * Show a friendly error message depicting an AJAX response that is not valid JSON
   163  * Show a friendly error message depicting an AJAX response that is not valid JSON
   156  * @param string Response text
   164  * @param string Response text