大家好我正在尝试在Titanium中集成web服务,但是当我按下按钮来调用它时,我的日志终止,我的应用程序冻结了。我收到没有错误消息。以下是我的代码:
Post_array.push({
variable1:value1,
variable2:value2
variable3:value3
});
var AddJobURL="http:/NUMBERS/MytestURL";
var AddJobxhr=Titanium.Network.createHTTPClient();
AddJobxhr.onload=function(){
console.log("Response text ----------------------"+ this.responseText);
var doc= JSON.parse(this.responseText);
};
AddJobxhr.onerror=function(e){
alert(e.error);
};
AddJobxhr.open('POST', AddJobURL);
AddJobxhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
AddJobxhr.send(Post_array);
编辑:我意识到了这个问题。我的问题是我的Post_array。我目前正在做的是按下一个按钮点击一个数组4个项目然后再按第二个不同的按钮点击另外4个项目然后发布这个数组但是他的点上的数组是[object Object],[object Object]我认为这是我的问题?任何想法如何解决?
答案 0 :(得分:2)
我想这里发送数据的格式不正确。
以下是您需要发送数据的格式:
AddJobxhr.send({
variable1: "value1",
variable2: "value2"
});
Post_array 是一个数组而不是上述格式。
您应该执行以下操作:
var Post_array = {};
Post_array = $.extend(Post_array, {
"variable1": "value1",
"variable2": "value2",
"variable3": "value3"
});
Post_array = $.extend(Post_array, {
"variable4": "value4",
"variable5": "value5",
"variable6": "value6"
});
AddJobxhr.send(Post_array);
答案 1 :(得分:1)
或者你可以这样做:
var Post_array = {};
// Doesn't have to be in quotes it's just the value you assign, strings are in quotes
// where as integers are not. Let us assume that value1, valu2 and value3 are the
// variable and they can hold anything;
Post_array["variable1"] = value1;
Post_array["variable2"] = value2;
Post_array["variable3"] = value3;
Post_array["variable4"] = value4;
Post_array["variable5"] = value5;
Post_array["variable6"] = value6;
AddJobxhr.send(Post_array);