2013-10-14 54 views
0

我试图张贴到使用钛的HttpClient像这样一个Web服务的数组:发布使用钛的HttpClient

var non_data = { 
     user_id: Facebook_ID, 
     "friends_ids[0]":friendIds[0], 
     "friends_ids[1]":friendIds[1] 


    }; 

    var non_xhr = Ti.Network.createHTTPClient({ 
     onload: function(){ 
      Titanium.API.info('Status: ' + this.status); 
      Titanium.API.info('ResponseText: ' + this.responseText); 
      Titanium.API.info('connectionType: ' + this.connectionType); 
      Titanium.API.info('location: ' + this.location); 
      alert("Get_Non_Friends response: " +this.responseText); 
     } 
    }); 

    non_xhr.open('POST', myURL); 
    non_xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    non_xhr.send(non_data); 

但它似乎并没有越来越数组元素的权利。任何人都可以告诉如何发布和params数组。

而且我发现TIMOB一个帖子,说做这样的事情,我目前想:

non_xhr.open('POST', myURL); 
    //non_xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    non_xhr.send('user_id=someData&friends_ids[0]=someData);  

谁能告诉我这个问题的最好方法?

回答

0

该问题似乎与发送方法。发送方法应该是这样的

non_xhr.send({paramName : non_data}); 

paramName是Web服务所需的名称。 Ex

non_xhr.send({ 
file: abc.jpg 

});

此外,它也建议有onerror方法就像onload方法。