@@ -11,7 +11,7 @@ Script: Request.JSONP.js
11
11
12
12
Request . JSONP = new Class ( {
13
13
14
- Implements : [ Chain , Events , Options ] ,
14
+ Implements : [ Chain , Events , Options , Log ] ,
15
15
16
16
options : { /*
17
17
onRetry: $empty(intRetries),
@@ -24,7 +24,7 @@ Request.JSONP = new Class({
24
24
retries : 0 ,
25
25
timeout : 0 ,
26
26
link : 'ignore' ,
27
- callBackKey : 'callback' ,
27
+ callbackKey : 'callback' ,
28
28
injectScript : document . head
29
29
} ,
30
30
@@ -57,7 +57,7 @@ Request.JSONP = new Class({
57
57
58
58
( function ( ) {
59
59
var script = this . getScript ( options ) ;
60
- MooTools . log ( 'JSONP retrieving script with url: ' + script . src ) ;
60
+ this . log ( 'JSONP retrieving script with url: ' + script . src ) ;
61
61
this . fireEvent ( 'request' , script ) ;
62
62
this . running = true ;
63
63
@@ -72,6 +72,7 @@ Request.JSONP = new Class({
72
72
} else if ( script && this . options . timeout ) {
73
73
script . destroy ( ) ;
74
74
this . cancel ( ) ;
75
+ this . fireEvent ( 'failure' ) ;
75
76
}
76
77
} ) . delay ( this . options . timeout , this ) ;
77
78
} ) . delay ( Browser . Engine . trident ? 50 : 0 , this ) ;
@@ -93,34 +94,28 @@ Request.JSONP = new Class({
93
94
case 'object' : case 'hash' : data = Hash . toQueryString ( options . data ) ;
94
95
}
95
96
96
- var script = new Element ( 'script' , {
97
- type : 'text/javascript' ,
98
- src : options . url +
99
- ( options . url . test ( '\\?' ) ? '&' :'?' ) +
100
- ( options . callBackKey || this . options . callBackKey ) +
101
- "=Request.JSONP.requests[" + index + "]" +
102
- ( data ? '&' + data : '' )
103
- } ) . inject ( this . options . injectScript ) ;
97
+ var src = options . url +
98
+ ( options . url . test ( '\\?' ) ? '&' :'?' ) +
99
+ ( options . callbackKey || this . options . callbackKey ) +
100
+ "=Request.JSONP.requests[" + index + "]" +
101
+ ( data ? '&' + data : '' ) ;
102
+
103
+ if ( src . length > 2083 ) this . log ( 'JSONP ' + src + ' will fail in Internet Explorer, which enforces a 2083 bytes length limit on URIs' ) ;
104
+
105
+ var script = new Element ( 'script' , { type : 'text/javascript' , src : src } ) ;
104
106
105
107
Request . JSONP . requests . push ( function ( data ) { this . success ( data , script ) ; } . bind ( this ) ) ;
106
108
107
- return script ;
109
+ return script . inject ( this . options . injectScript ) ;
108
110
} ,
109
111
110
112
success : function ( data , script ) {
111
113
if ( script ) script . destroy ( ) ;
112
114
this . running = false ;
113
- MooTools . log ( 'JSONP successfully retrieved: ' , data ) ;
114
- this . fireEvent ( 'complete' , data ) . fireEvent ( 'success' , data ) . callChain ( ) ;
115
+ this . log ( 'JSONP successfully retrieved: ' , data ) ;
116
+ this . fireEvent ( 'complete' , [ data ] ) . fireEvent ( 'success' , [ data ] ) . callChain ( ) ;
115
117
}
116
118
117
119
} ) ;
118
120
119
- Request . JSONP . requests = [ ] ;
120
-
121
- $extend ( MooTools , {
122
- logged : [ ] ,
123
- log : function ( ) {
124
- MooTools . logged . push ( arguments ) ;
125
- }
126
- } ) ;
121
+ Request . JSONP . requests = [ ] ;
0 commit comments