Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4267: prototype-diff2.txt

File prototype-diff2.txt, 1.5 kB (added by blair, 3 years ago)

Better version that caches tries to get a copy of this.transport.status once and catches that

Line 
1 Index: public/javascripts/prototype.js
2 ===================================================================
3 --- public/javascripts/prototype.js     (revision 103904)
4 +++ public/javascripts/prototype.js     (revision 103905)
5 @@ -609,9 +609,19 @@
6    },
7  
8    responseIsSuccess: function() {
9 -    return this.transport.status == undefined
10 -        || this.transport.status == 0
11 -        || (this.transport.status >= 200 && this.transport.status < 300);
12 +    /* Firefox does not have a transport.status member variable when
13 +     * there is no server listening on the port the AJAX call was
14 +     * made to. */
15 +    var status;
16 +    try {
17 +      status = this.transport.status;
18 +    } catch (e) {
19 +      return 0;
20 +    }
21 +
22 +    return status == undefined
23 +        || status == 0
24 +        || (status >= 200 && status < 300);
25    },
26  
27    responseIsFailure: function() {
28 @@ -714,8 +724,16 @@
29      var transport = this.transport, json = this.evalJSON();
30  
31      if (event == 'Complete') {
32 +      /* Firefox does not have a transport.status member variable when
33 +       * there is no server listening on the port the AJAX call was
34 +       * made to. */
35 +      var status = 'Failure';
36        try {
37 -        (this.options['on' + this.transport.status]
38 +        status = this.transport.status;
39 +      } catch (e) {}
40 +
41 +      try {
42 +        (this.options['on' + status]
43           || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
44           || Prototype.emptyFunction)(transport, json);
45        } catch (e) {