【发布时间】:2016-05-26 04:56:33
【问题描述】:
我们为 android 和 ios 使用来自 serviceutility.js 的相同的 RESTful Web 服务代码。但是该服务受到打击,并且仅在 ios 中检索值。相同的代码在 android 中不起作用,我们收到以下错误:
[ERROR] : TiExceptionHandler: (main) [2,821093] - 在alloy/controllers/home.js:25,32
[ERROR] : TiExceptionHandler: (main) [0,821093] - 消息:未捕获的 TypeError:无法读取 null 的属性“状态”
[ERROR] : TiExceptionHandler: (main) [0,821093] - 来源:if ("1" == response.status) alert(response.message);否则如果(“0”
[错误]:V8Exception:Alloy/controllers/home.js:25 发生异常:未捕获类型错误:无法读取 null 的属性“状态”。
Titanium SDK 是 5.1.2 GA
exports.login = function(user, cb) {
var response = null;
if (Ti.Network.online) {
var xhr = Ti.Network.createHTTPClient({
timeout : 10000,
validatesSecureCertificate : false
});
xhr.onload = function() {// Onload
var responseTxt = this.responseText == '' ? '{}' : this.responseText;
try {
response = JSON.parse(responseTxt);
cb(response, 'SUCCESS');
} catch(e) {
cb(response, 'ERROR');
}
};
xhr.onerror = function(e) {
if (xhr.status === 0) {
cb(response, 'TIMEDOUT');
} else {
cb(response, 'ERROR');
}
};
url = "https://";
var postData = {
employeeId : user.employeeId,
password : user.password
};
xhr.open('POST', url);
xhr.setTimeout(10000);
xhr.setRequestHeader('employeeId', user.employeeId);
xhr.setRequestHeader('password', user.password);
xhr.send();} else {
cb(response, 'NO_NETWORK');
}};
下面的代码是 index.js 文件的实际检索值发生的地方。
if (Ti.Network.online) {
loginUtil.login(user, function(response, status) {
Ti.API.info("status----" + status);
if (response.status == "0") {
Ti.API.info("status== " + response.status);
Ti.App.role = response.role;
Alloy.createController('home', {employeeId:$.userTextField.value,password:$.passwordTextField.value,from:"index"}).getView().open();
} else if (response.status == '1') {
alert(response.message);
} else {
alert("Please enter the correct credentials");
}
});
}
请帮助我们。
【问题讨论】:
-
您需要显示一些代码... API 调用的成功回调中包含什么,因为这是一个常规的 javascript 错误
-
.. 或尝试 Reste:github.com/jasonkneen/RESTe
-
嗨,Rene,感谢您的回复。我通过添加编码部分来编辑我的问题。请参考。
标签: appcelerator appcelerator-titanium