【发布时间】:2015-03-04 00:52:37
【问题描述】:
var xhr=Titanium.Network.createHTTPClient({
onload:function(e){
if(this.status == '200'){
Ti.API.info('got my response, http status code ' + this.status);
if(this.readyState == 4){
var response=JSON.parse(this.responseText);
success = true;
}
else{
alert('HTTP Ready State != 4');
}
}
else{
alert('HTTP Error Response Status Code = '+this.status);
Ti.API.error("Error =>"+this.response);
}
},
});
xhr.onerror = function(e){
};
xhr.open("POST","http://localhost:23003/api/user?username=dp&password=123456" ,true);//ADD your URL
xhr.setRequestHeader("content-type", "application/json");
xhr.send(); // Taa da
您好,上面提到的是我的代码,我正在尝试向本地服务器进程发送一个发布请求,如 open 方法中所述。但是我使用了一些控制台消息来查看这些返回的对象
- this.responseText -- 此文本为空白。 (我知道 java 脚本返回 null 的方式不同,并且警报消息将“null”显示为 null。)
- this.status -- 返回“0”
- this.readyState 返回 4
- var 响应 = JSON.parse();是空白文本
- 我也尝试将内容类型更改为 -application/x-www-form-urlencoded,但结果相同
我不知道我错在哪里。任何帮助将不胜感激。感谢您的宝贵时间。
【问题讨论】:
-
a/ 您可以尝试将 url 中的 localhost 更改为您的 ip 地址。 b/ 尝试使用postman 检查网络服务以确认网络服务工作正常。
标签: javascript post titanium appcelerator onload