钛 xhr 事件未触发
我一直在尝试让一个简单的 xhr 请求工作,但由于某些未知的原因什么也没有发生,甚至 onerror 函数也没有启动。
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
Titanium.API.log('Success');
}
xhr.onerror = function() {
Titanium.API.log('Error');
}
xhr.open("GET","http://www.google.com/");
xhr.send();
我已经在一个新创建的项目中尝试过此操作,但仍然没有运气。使用小告密者,我注意到应用程序已与给定的网址建立了连接......但仍然没有任何触发。
我缺少什么?
我也在 iPhone 模拟器上进行开发。
I have been trying to get a simple xhr request to work but for some unknown reasons nothing happens, not even the onerror function fires off.
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
Titanium.API.log('Success');
}
xhr.onerror = function() {
Titanium.API.log('Error');
}
xhr.open("GET","http://www.google.com/");
xhr.send();
I have tried this with a new created project and still no luck. Using little snitch I noticed that a connection is made by the app to the given url ... but still nothing fires off.
What am I missing?
Also I'm developing on an iPhone Simulator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 XHR 请求没有任何问题 - Titanium.API.log 函数需要两个参数,但您只给它一个参数,所以它可能只是没有打印到控制台。 Titanium 文档目前已关闭,因此我无法将您链接到正确的 API,但是如果您将代码更改为使用 Ti.API.info,例如,您应该会看到打印的内容。这对我有用:
I don't think there's anything wrong with the XHR request - the Titanium.API.log function takes two arguments, but you're only giving it one, so it's probably just not printing to the console. The Titanium documentation is down at the moment so I can't link you to the correct API, but if you change your code to use Ti.API.info, for example, you should see something printed. This works for me: