Changeset 1100 for trunk


Ignore:
Timestamp:
10/28/08 15:00:35 (10 years ago)
Author:
douglas
Message:

FIXED Ticket #1317 Add failure handlers to getback and postback functions
CHANGED Relaxed Success handling to support all HTTP success codes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/XinhaCore.js

    r1099 r1100  
    61886188}; 
    61896189 
    6190 /** Use XMLHTTPRequest to post some data back to the server and do something 
    6191  *  with the response (asyncronously!), this is used by such things as the tidy functions 
    6192  *  @param {String} url The address for the HTTPRequest 
    6193  *  @param {Object} data The data to be passed to the server like {name:"value"} 
    6194  *  @param {Function} handler A function that is called when an answer is received from the server with the responseText  
    6195  *                             as argument                              
     6190/** 
     6191 * Use XMLHTTPRequest to post some data back to the server and do something 
     6192 * with the response (asyncronously!), this is used by such things as the tidy 
     6193 * functions 
     6194 * @param {String} url The address for the HTTPRequest 
     6195 * @param {Object} data The data to be passed to the server like {name:"value"} 
     6196 * @param {Function} success A function that is called when an answer is 
     6197 *                           received from the server with the responseText as argument. 
     6198 * @param {Function} failure A function that is called when we fail to receive 
     6199 *                           an answer from the server. We pass it the request object. 
    61966200 */ 
    61976201  
     
    62016205// then Xinha._postback_send_charset will be set to false and the request tried again (once) 
    62026206Xinha._postback_send_charset = true; 
    6203 Xinha._postback = function(url, data, handler) 
     6207Xinha._postback = function(url, data, success, failure) 
    62046208{ 
    62056209  var req = null; 
     
    62236227    if ( req.readyState == 4 ) 
    62246228    { 
    6225       if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) 
    6226       { 
    6227         if ( typeof handler == 'function' ) 
     6229      if ( ((req.status / 100) == 2) || Xinha.isRunLocally && req.status == 0 ) 
     6230      { 
     6231        if ( typeof success == 'function' ) 
    62286232        { 
    6229           handler(req.responseText, req); 
     6233          success(req.responseText, req); 
    62306234        } 
    62316235      } 
     
    62336237      {         
    62346238        Xinha._postback_send_charset = false; 
    6235         Xinha._postback(url,data,handler); 
     6239        Xinha._postback(url,data,success, failure); 
     6240      } 
     6241      else if (typeof failure == 'function') 
     6242      { 
     6243        failure(req); 
    62366244      } 
    62376245      else 
     
    62476255  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'+(Xinha._postback_send_charset ? '; charset=UTF-8' : '')); 
    62486256 
    6249   //alert(content); 
    62506257  req.send(content); 
    62516258}; 
    62526259 
    6253 /** Use XMLHTTPRequest to receive some data from the server and do something 
    6254  *  with the it (asyncronously!) 
    6255  *  @param {String} url The address for the HTTPRequest 
    6256  *  @param {Function} handler A function that is called when an answer is received from the server with the responseText  
    6257  *                             as argument                              
    6258  */ 
    6259 Xinha._getback = function(url, handler) 
     6260/**  
     6261 * Use XMLHTTPRequest to receive some data from the server and do something 
     6262 * with the it (asyncronously!) 
     6263 * @param {String} url The address for the HTTPRequest 
     6264 * @param {Function} success A function that is called when an answer is 
     6265 *                           received from the server with the responseText as argument. 
     6266 * @param {Function} failure A function that is called when we fail to receive 
     6267 *                           an answer from the server. We pass it the request object. 
     6268 */ 
     6269Xinha._getback = function(url, success, failure) 
    62606270{ 
    62616271  var req = null; 
     
    62666276    if ( req.readyState == 4 ) 
    62676277    { 
    6268       if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) 
    6269       { 
    6270         handler(req.responseText, req); 
     6278      if ( ((req.status / 100) == 2) || Xinha.isRunLocally && req.status == 0 ) 
     6279      { 
     6280        success(req.responseText, req); 
     6281      } 
     6282      else if (typeof failure == 'function') 
     6283      { 
     6284        failure(req); 
    62716285      } 
    62726286      else 
     
    62916305    if ( req.readyState == 4 ) 
    62926306    { 
    6293       if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) 
     6307      if ( ((req.status / 100) == 2) || Xinha.isRunLocally && req.status == 0 ) 
    62946308      { 
    62956309        if (successHandler) successHandler(req); 
     
    63226336  req.open('GET', url, false); 
    63236337  req.send(null); 
    6324   if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) 
     6338  if ( ((req.status / 100) == 2) || Xinha.isRunLocally && req.status == 0 ) 
    63256339  { 
    63266340    return req.responseText; 
Note: See TracChangeset for help on using the changeset viewer.