在请求中使用数组发送qx.io.request.Xhr请求

时间:2016-05-04 18:46:59

标签: javascript xmlhttprequest qooxdoo

根据documentation,requestData可以处理ArrayBuffer参数。但是当我尝试这个时:

var buf = new ArrayBuffer(16); 
var ar = new Uint8Array(buf); 
for(var i = 0; i < ar.length; i++) 
    ar[i] = i * 10; 
request = new qx.io.request.Xhr(); 
request.setUrl(url); 
request.setRequestData(buf); 
request.send(); 

我收到以下错误:

Error: params must be either string or object 

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您必须将方法设置为POST

request.setMethod('POST'); 

在致电request.send()之前。所以你的例子看起来像这样:

var buf = new ArrayBuffer(16); 
var ar = new Uint8Array(buf); 
for(var i = 0; i < ar.length; i++) {
    ar[i] = i * 10; 
}
request = new qx.io.request.Xhr().set({
    url: url,
    requestData: buf,
    method: 'POST'
}).send();

另见https://github.com/qooxdoo/qooxdoo/blob/master/framework/source/class/qx/test/bom/request/SimpleXhr.js#L337