Skip to content

Commit 7a21df1

Browse files
committed
Added sendPostArrayBuffer in XHRTest.js
1 parent a2c30e6 commit 7a21df1

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

samples/js-tests/src/XHRTest/XHRTest.js

+31-4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var XHRTestLayer = cc.Layer.extend({
8181
this.sendGetRequest();
8282
this.sendPostPlainText();
8383
this.sendPostForms();
84+
this.sendPostArrayBuffer();
8485
},
8586

8687
sendGetRequest: function() {
@@ -113,7 +114,7 @@ var XHRTestLayer = cc.Layer.extend({
113114
var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 12);
114115
this.addChild(statusPostLabel, 1);
115116

116-
statusPostLabel.x = winSize.width / 10 * 3;
117+
statusPostLabel.x = winSize.width / 10 * 2.5;
117118
statusPostLabel.y = winSize.height - 100;
118119
ensureLeftAligned(statusPostLabel);
119120
statusPostLabel.setString("Status: Send Post Request to httpbin.org with plain text");
@@ -122,7 +123,7 @@ var XHRTestLayer = cc.Layer.extend({
122123
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
123124
this.addChild(responseLabel, 1);
124125
ensureLeftAligned(responseLabel);
125-
responseLabel.x = winSize.width / 10 * 3;
126+
responseLabel.x = winSize.width / 10 * 2.5;
126127
responseLabel.y = winSize.height / 2;
127128

128129
var xhr = cc.loader.getXMLHttpRequest();
@@ -138,7 +139,7 @@ var XHRTestLayer = cc.Layer.extend({
138139
var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 12);
139140
this.addChild(statusPostLabel, 1);
140141

141-
statusPostLabel.x = winSize.width / 10 * 7;
142+
statusPostLabel.x = winSize.width / 10 * 5;
142143
statusPostLabel.y = winSize.height - 100;
143144
ensureLeftAligned(statusPostLabel);
144145
statusPostLabel.setString("Status: Send Post Request to httpbin.org width form data");
@@ -147,7 +148,7 @@ var XHRTestLayer = cc.Layer.extend({
147148
this.addChild(responseLabel, 1);
148149

149150
ensureLeftAligned(responseLabel);
150-
responseLabel.x = winSize.width / 10 * 7;
151+
responseLabel.x = winSize.width / 10 * 5;
151152
responseLabel.y = winSize.height / 2;
152153

153154
var xhr = cc.loader.getXMLHttpRequest();
@@ -167,6 +168,32 @@ var XHRTestLayer = cc.Layer.extend({
167168
xhr.send(args);
168169
},
169170

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+
170197
scrollViewDidScroll:function (view) {
171198
},
172199
scrollViewDidZoom:function (view) {

0 commit comments

Comments
 (0)