@@ -81,6 +81,7 @@ var XHRTestLayer = cc.Layer.extend({
81
81
this . sendGetRequest ( ) ;
82
82
this . sendPostPlainText ( ) ;
83
83
this . sendPostForms ( ) ;
84
+ this . sendPostArrayBuffer ( ) ;
84
85
} ,
85
86
86
87
sendGetRequest : function ( ) {
@@ -113,7 +114,7 @@ var XHRTestLayer = cc.Layer.extend({
113
114
var statusPostLabel = new cc . LabelTTF ( "Status:" , "Thonburi" , 12 ) ;
114
115
this . addChild ( statusPostLabel , 1 ) ;
115
116
116
- statusPostLabel . x = winSize . width / 10 * 3 ;
117
+ statusPostLabel . x = winSize . width / 10 * 2.5 ;
117
118
statusPostLabel . y = winSize . height - 100 ;
118
119
ensureLeftAligned ( statusPostLabel ) ;
119
120
statusPostLabel . setString ( "Status: Send Post Request to httpbin.org with plain text" ) ;
@@ -122,7 +123,7 @@ var XHRTestLayer = cc.Layer.extend({
122
123
var responseLabel = new cc . LabelTTF ( "" , "Thonburi" , 16 ) ;
123
124
this . addChild ( responseLabel , 1 ) ;
124
125
ensureLeftAligned ( responseLabel ) ;
125
- responseLabel . x = winSize . width / 10 * 3 ;
126
+ responseLabel . x = winSize . width / 10 * 2.5 ;
126
127
responseLabel . y = winSize . height / 2 ;
127
128
128
129
var xhr = cc . loader . getXMLHttpRequest ( ) ;
@@ -138,7 +139,7 @@ var XHRTestLayer = cc.Layer.extend({
138
139
var statusPostLabel = new cc . LabelTTF ( "Status:" , "Thonburi" , 12 ) ;
139
140
this . addChild ( statusPostLabel , 1 ) ;
140
141
141
- statusPostLabel . x = winSize . width / 10 * 7 ;
142
+ statusPostLabel . x = winSize . width / 10 * 5 ;
142
143
statusPostLabel . y = winSize . height - 100 ;
143
144
ensureLeftAligned ( statusPostLabel ) ;
144
145
statusPostLabel . setString ( "Status: Send Post Request to httpbin.org width form data" ) ;
@@ -147,7 +148,7 @@ var XHRTestLayer = cc.Layer.extend({
147
148
this . addChild ( responseLabel , 1 ) ;
148
149
149
150
ensureLeftAligned ( responseLabel ) ;
150
- responseLabel . x = winSize . width / 10 * 7 ;
151
+ responseLabel . x = winSize . width / 10 * 5 ;
151
152
responseLabel . y = winSize . height / 2 ;
152
153
153
154
var xhr = cc . loader . getXMLHttpRequest ( ) ;
@@ -167,6 +168,32 @@ var XHRTestLayer = cc.Layer.extend({
167
168
xhr . send ( args ) ;
168
169
} ,
169
170
171
+ sendPostArrayBuffer : function ( ) {
172
+ var statusPostLabel = new cc . LabelTTF ( "Status:" , "Thonburi" , 12 ) ;
173
+ this . addChild ( statusPostLabel , 1 ) ;
174
+
175
+ statusPostLabel . x = winSize . width / 10 * 7.5 ;
176
+ statusPostLabel . y = winSize . height - 100 ;
177
+ ensureLeftAligned ( statusPostLabel ) ;
178
+ statusPostLabel . setString ( "Status: Send Post Request to httpbin.org with ArrayBuffer" ) ;
179
+
180
+
181
+ var responseLabel = new cc . LabelTTF ( "" , "Thonburi" , 16 ) ;
182
+ this . addChild ( responseLabel , 1 ) ;
183
+ ensureLeftAligned ( responseLabel ) ;
184
+ responseLabel . x = winSize . width / 10 * 7.5 ;
185
+ responseLabel . y = winSize . height / 2 ;
186
+
187
+ var xhr = cc . loader . getXMLHttpRequest ( ) ;
188
+ streamXHREventsToLabel ( xhr , statusPostLabel , responseLabel , "POST" ) ;
189
+
190
+ xhr . open ( "POST" , "http://httpbin.org/post" ) ;
191
+ //set Content-type "text/plain" to post ArrayBuffer or ArrayBufferView
192
+ xhr . setRequestHeader ( "Content-Type" , "text/plain" ) ;
193
+ // Uint8Array is an ArrayBufferView
194
+ xhr . send ( new Uint8Array ( [ 1 , 2 , 3 , 4 , 5 ] ) ) ;
195
+ } ,
196
+
170
197
scrollViewDidScroll :function ( view ) {
171
198
} ,
172
199
scrollViewDidZoom :function ( view ) {
0 commit comments