[英]web service call causing my app to crash
Hi all I am trying to integrate a webservice in Titanium but when I press the button to call it my log is terminated and my app freezes. 大家好,我试图在Titanium中集成Web服务,但是当我按下按钮调用它时,我的日志终止并且我的应用程序冻结。 I am getting no error messages.
我没有收到任何错误消息。 Below is my code:
下面是我的代码:
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);
EDIT: I've realised the problem. 编辑:我已经意识到了问题。 My issue is my Post_array.
我的问题是我的Post_array。 What I am currently doing is pushing 4 items to an array on a button click and then pushing an additional 4 items on a second different button click and then posting this array but the array at his point is [object Object],[object Object] I think this is my issue?
我目前正在做的是在单击按钮时将4个项目推入数组,然后在第二次单击按钮时将另外4个项目推入数组,然后发布此数组,但该数组在他的位置是[object Object],[object Object]我认为这是我的问题? Any ideas how to solve?
任何想法如何解决?
The format of the sending data is not correct here I guess. 我猜这里发送数据的格式不正确。
Below is the format in which you need to send the data: 以下是您需要发送数据的格式:
AddJobxhr.send({
variable1: "value1",
variable2: "value2"
});
Where as Post_array is an array and not in the above format. 其中, Post_array是数组,而不是上述格式。
You should do something like: 您应该执行以下操作:
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);
Alternatively you can do: 或者,您可以执行以下操作:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.