| | @@ -94,11 +94,12 @@ |
| 94 | 94 | If the str argument is not passed (arguments.length==0) then |
| 95 | 95 | window.location.search.substring(1) is used by default. If |
| 96 | 96 | neither str is passed in nor window exists then false is returned. |
| 97 | 97 | |
| 98 | 98 | On success it returns an Object containing the key/value pairs |
| 99 | | - parsed from the string. |
| 99 | + parsed from the string. Keys which have no value are treated |
| 100 | + has having the boolean true value. |
| 100 | 101 | |
| 101 | 102 | FIXME: for keys in the form "name[]", build an array of results, |
| 102 | 103 | like PHP does. |
| 103 | 104 | |
| 104 | 105 | */ |
| | @@ -186,25 +187,29 @@ |
| 186 | 187 | object which act as wrappers for backend-specific functionality. As |
| 187 | 188 | a simple example: |
| 188 | 189 | |
| 189 | 190 | @code |
| 190 | 191 | cgi.login = function(name,pw,ajajOpt) { |
| 191 | | - this.sendRequest( {name:name, password:pw}, ajajOpt ); |
| 192 | + this.sendRequest( |
| 193 | + {command:"json/login", |
| 194 | + name:name, |
| 195 | + password:pw |
| 196 | + }, ajajOpt ); |
| 192 | 197 | }; |
| 193 | 198 | @endcode |
| 194 | 199 | |
| 195 | 200 | TODOs: |
| 196 | 201 | |
| 197 | 202 | - Caching of page-load requests, with a configurable lifetime. |
| 198 | 203 | |
| 199 | | - - Use-cases like the above login() function are a tiny bit |
| 200 | | - problematic to implement when each request has a different URL |
| 201 | | - path (i know this from the whiki implementation). This is partly |
| 202 | | - a side-effect of design descisions made back in the very first |
| 203 | | - days of this code's life. i need to go through and see where i |
| 204 | | - can bend those conventions a bit (where it won't break my other |
| 205 | | - apps unduly). |
| 204 | + - Use-cases like the above login() function are a tiny bit |
| 205 | + problematic to implement when each request has a different URL |
| 206 | + path (i know this from the whiki and fossil implementations). |
| 207 | + This is partly a side-effect of design descisions made back in |
| 208 | + the very first days of this code's life. i need to go through |
| 209 | + and see where i can bend those conventions a bit (where it won't |
| 210 | + break my other apps unduly). |
| 206 | 211 | */ |
| 207 | 212 | WhAjaj.Connector = function(opt) |
| 208 | 213 | { |
| 209 | 214 | if(WhAjaj.isObject(opt)) this.options = opt; |
| 210 | 215 | //TODO?: this.$cache = {}; |
| | @@ -284,11 +289,11 @@ |
| 284 | 289 | not. Not all concrete WhAjaj.Connector.sendImpl() |
| 285 | 290 | implementations can support this. Interestingly, at |
| 286 | 291 | least one popular AJAX toolkit does not document |
| 287 | 292 | supporting _synchronous_ AJAX operations. All common |
| 288 | 293 | browser-side implementations support async operation, but |
| 289 | | - non-browser implementations migth not. |
| 294 | + non-browser implementations might not. |
| 290 | 295 | */ |
| 291 | 296 | asynchronous:true, |
| 292 | 297 | |
| 293 | 298 | /** |
| 294 | 299 | A HTTP authentication login name for the AJAX |
| | @@ -310,28 +315,32 @@ |
| 310 | 315 | WhAjaj.Connector.sendImpl() implementations can support this. |
| 311 | 316 | */ |
| 312 | 317 | timeout:10000, |
| 313 | 318 | |
| 314 | 319 | /** |
| 315 | | - If an AJAJ request receives JSON data from the back-end, that |
| 316 | | - data is passed as a plain Object as the response parameter |
| 317 | | - (exception: in jsonp mode it is passed a string). The initiating |
| 318 | | - request object is passed as the second parameter, but clients |
| 319 | | - can normally ignore it (only those which need a way to map |
| 320 | | - specific requests to responses will need it). The 3rd parameter |
| 321 | | - is the same as the 'this' object for the context of the callback, |
| 322 | | - but is provided because the instance-level callbacks (set in |
| 323 | | - (WhAjaj.Connector instance).callbacks, require it in some |
| 324 | | - cases (because their 'this' is different!). |
| 325 | | - |
| 326 | | - Note that the response might contain error information which |
| 327 | | - comes from the back-end. The difference between this error info |
| 328 | | - and the info passed to the onError() callback is that this data |
| 329 | | - indicates an application-level error, whereas onError() is used |
| 330 | | - to report connection-level problems or when the backend produces |
| 331 | | - non-JSON data (which, when not in jsonp mode, is unexpected and |
| 332 | | - is as fatal to the request as a connection error). |
| 320 | + If an AJAJ request receives JSON data from the back-end, |
| 321 | + that data is passed as a plain Object as the response |
| 322 | + parameter (exception: in jsonp mode it is passed a |
| 323 | + string (why???)). The initiating request object is |
| 324 | + passed as the second parameter, but clients can normally |
| 325 | + ignore it (only those which need a way to map specific |
| 326 | + requests to responses will need it). The 3rd parameter |
| 327 | + is the same as the 'this' object for the context of the |
| 328 | + callback, but is provided because the instance-level |
| 329 | + callbacks (set in (WhAjaj.Connector instance).callbacks, |
| 330 | + require it in some cases (because their 'this' is |
| 331 | + different!). |
| 332 | + |
| 333 | + Note that the response might contain error information |
| 334 | + which comes from the back-end. The difference between |
| 335 | + this error info and the info passed to the onError() |
| 336 | + callback is that this data indicates an |
| 337 | + application-level error, whereas onError() is used to |
| 338 | + report connection-level problems or when the backend |
| 339 | + produces non-JSON data (which, when not in jsonp mode, |
| 340 | + is unexpected and is as fatal to the request as a |
| 341 | + connection error). |
| 333 | 342 | */ |
| 334 | 343 | onResponse: function(response, request, opt){}, |
| 335 | 344 | |
| 336 | 345 | /** |
| 337 | 346 | If an AJAX request fails to establish a connection or it |
| | @@ -760,12 +769,10 @@ |
| 760 | 769 | var timeout = args.timeout || 10000/*arbitrary!*/; |
| 761 | 770 | var hitTimeout = false; |
| 762 | 771 | var done = false; |
| 763 | 772 | var tmid /* setTimeout() ID */; |
| 764 | 773 | var whself = this; |
| 765 | | - //if( json ) json = json.replace(/ö/g,"\\u00f6") /* ONLY FOR A SPECIFIC TEST */; |
| 766 | | - //alert( 'json=\n'+json ); |
| 767 | 774 | function handleTimeout() |
| 768 | 775 | { |
| 769 | 776 | hitTimeout = true; |
| 770 | 777 | if( ! done ) |
| 771 | 778 | { |
| 772 | 779 | |