Tobie Langel wrote:
>> So Tobie, how would you use the file protocol for an ajax request?
>>     
> It's mainly a backwards compatibility issue (plus it can be useful for
> testing purposes).
>   
Tobie,

Looking at John Resig's jQuery, I see that the file protocol is 
considered.  However, it doesn't account for URLs which have links to 
static content as you mentioned might be used in testing.

    httpSuccess: function( r ) {
        try {
            return !r.status && location.protocol == "file:" ||
                ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
                jQuery.browser.safari && r.status == undefined;
        } catch(e){}
        return false;
    },



Below is an untested patch.  Is it in line with your vision of 
functionality?  It allows URLs to call local files, eliminates the "on0" 
callback and calls "onSuccess" for both local files and successful 
requests.  My question is: Is it possible to detect when local files 
fail to load?

- Ken Snyder



Index: ajax.js
===================================================================
--- ajax.js    (revision 7468)
+++ ajax.js    (working copy)
@@ -74,6 +74,9 @@
 
   request: function(url) {
     this.url = url;
+    this.isLocalUrl = this.url.indexOf('file:') === 0 ||
+      (location.protocol == 'file:' && this.url.indexOf('://') == -1);
     this.method = this.options.method;
     var params = Object.clone(this.options.parameters);
 
@@ -162,24 +165,32 @@
  
   success: function() {
     var status = this.getStatus();
-    return !status || (status >= 200 && status < 300);
+    return status == 304 || (status >= 200 && status < 300) || 
(this.isLocalUrl && !status);
   },
-   
+ 
   getStatus: function() {
     try {
-      return this.transport.status || 0;
-    } catch (e) { return 0 }
-  },
- 
+      var status = this.transport.status;
+      if (this.isLocalUrl)
+        return 200;
+      if ([1223, 12002, 12029, 12030, 12031, 12152].member(status))
+        return 0;
+      return status;
+    } catch(e) {
+      return 0;
+    }
+  }, 
+
   respondToReadyState: function(readyState) {
-    var state = Ajax.Request.Events[readyState], response = new 
Ajax.Response(this);
+    var state = Ajax.Request.Events[readyState];
+    var json = this.evalJSON();
 
     if (state == 'Complete') {
       try {
         this._complete = true;
-        (this.options['on' + response.status]
+        (this.options['on' + (this.getStatus() || 'Exception')]
          || this.options['on' + (this.success() ? 'Success' : 'Failure')]
-         || Prototype.emptyFunction)(response, response.headerJSON);
+         || Prototype.emptyFunction)(this.transport, json);
       } catch (e) {
         this.dispatchException(e);
       }





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to