钛 xhr 事件未触发

发布于 2024-12-20 22:10:54 字数 473 浏览 3 评论 0原文

我一直在尝试让一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栩栩如生 2024-12-27 22:10:54

我认为 XHR 请求没有任何问题 - Titanium.API.log 函数需要两个参数,但您只给它一个参数,所以它可能只是没有打印到控制台。 Titanium 文档目前已关闭,因此我无法将您链接到正确的 API,但是如果您将代码更改为使用 Ti.API.info,例如,您应该会看到打印的内容。这对我有用:

var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
    Titanium.API.info('Success');
}
xhr.onerror = function() {
    Titanium.API.info('Error');
}

xhr.open("GET","http://www.google.com/");
xhr.send();

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:

var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
    Titanium.API.info('Success');
}
xhr.onerror = function() {
    Titanium.API.info('Error');
}

xhr.open("GET","http://www.google.com/");
xhr.send();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文