Changeset 1100
- Timestamp:
- 10/28/08 15:00:35 (5 years ago)
- Files:
-
- 1 modified
-
trunk/XinhaCore.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/XinhaCore.js
r1099 r1100 6188 6188 }; 6189 6189 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. 6196 6200 */ 6197 6201 … … 6201 6205 // then Xinha._postback_send_charset will be set to false and the request tried again (once) 6202 6206 Xinha._postback_send_charset = true; 6203 Xinha._postback = function(url, data, handler)6207 Xinha._postback = function(url, data, success, failure) 6204 6208 { 6205 6209 var req = null; … … 6223 6227 if ( req.readyState == 4 ) 6224 6228 { 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' ) 6228 6232 { 6229 handler(req.responseText, req);6233 success(req.responseText, req); 6230 6234 } 6231 6235 } … … 6233 6237 { 6234 6238 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); 6236 6244 } 6237 6245 else … … 6247 6255 req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'+(Xinha._postback_send_charset ? '; charset=UTF-8' : '')); 6248 6256 6249 //alert(content);6250 6257 req.send(content); 6251 6258 }; 6252 6259 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 */ 6269 Xinha._getback = function(url, success, failure) 6260 6270 { 6261 6271 var req = null; … … 6266 6276 if ( req.readyState == 4 ) 6267 6277 { 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); 6271 6285 } 6272 6286 else … … 6291 6305 if ( req.readyState == 4 ) 6292 6306 { 6293 if ( req.status == 200|| Xinha.isRunLocally && req.status == 0 )6307 if ( ((req.status / 100) == 2) || Xinha.isRunLocally && req.status == 0 ) 6294 6308 { 6295 6309 if (successHandler) successHandler(req); … … 6322 6336 req.open('GET', url, false); 6323 6337 req.send(null); 6324 if ( req.status == 200|| Xinha.isRunLocally && req.status == 0 )6338 if ( ((req.status / 100) == 2) || Xinha.isRunLocally && req.status == 0 ) 6325 6339 { 6326 6340 return req.responseText;
