ajax代码在android上工作,在iOS上失败

发布于 2025-01-06 11:35:06 字数 738 浏览 1 评论 0原文

我写了一个在安卓上完美运行的应用程序。我已经为 iOS 版本输入了相同的代码,并将其加载到我的 iPod touch 2nd gen 上。应用程序中的所有内容都显示正常,但似乎无法发送/接收 ajax 请求。在我的应用程序上有一个登录,我使用 ajax 调用来登录。ipod 可以正常连接到互联网,所以我不太确定为什么这段代码不起作用。

是因为手机旧了?我构建的应用程序支持 iOS 3.0。还有什么可能呢?

谢谢

编辑: 是的,这纯粹是一个网络应用程序,我正在处理 ajax 问题。这是特别的部分:

$.ajax({
    type: "POST",
    url: "https://website.com/a/login/",
    data: data,
    dataType: "json",
    async: false
}).success(function (data) {
    window.localStorage.setItem("token", data["token"]);
    window.localStorage.setItem("oid", data["oid"]);
    //   alert(data["token"]);
}).error(function (a, b, c) {
    $('#submit').button('enable');
    alert("One of your credentials is incorrect, please try again");
});

I have written an app that works perfectly on the android. I have put in the same code for the iOS version and loaded it up on my ipod touch 2nd gen. Everything in the app shows up fine, but it seems unable to send/receive ajax request. On my app there is a login and I use an ajax call to log in. The ipod is connecting to the internet fine, so I'm not quite sure why this code isn't working.

Is it because its an old phone? I built the app to support as far as iOS 3.0. What else could be possible?

thanks

EDIT:
yes this is purely a webapp, and I'm dealing with ajax issues. This is the part in particular:

$.ajax({
    type: "POST",
    url: "https://website.com/a/login/",
    data: data,
    dataType: "json",
    async: false
}).success(function (data) {
    window.localStorage.setItem("token", data["token"]);
    window.localStorage.setItem("oid", data["oid"]);
    //   alert(data["token"]);
}).error(function (a, b, c) {
    $('#submit').button('enable');
    alert("One of your credentials is incorrect, please try again");
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

別甾虛僞 2025-01-13 11:35:06

我要检查的两件事...

1 - 您是否在 PhoneGap.plist 中的“ExternalHosts”键下添加了主机?

2 - SSL 证书是自签名的吗? <- 如果没有 Objective-C 插件,这将无法工作

这两个项目都在这里讨论: http://wiki.phonegap.com/w/page/41631150/PhoneGap%20for%20iOS%20FAQ

2 things I would check...

1 - did you add the host in PhoneGap.plist under the "ExternalHosts" key?

2 - is the SSL cert self signed? <- this doesn't work without an Objective-C plugin

Both items are discussed here: http://wiki.phonegap.com/w/page/41631150/PhoneGap%20for%20iOS%20FAQ

述情 2025-01-13 11:35:06

如果 Deric 的第一个建议不起作用,您可以尝试将其添加到 AppDelegate.m 的末尾

@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES; 
}
@end

If Deric's first suggestion didn't work you can try to add this at the end of you AppDelegate.m

@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES; 
}
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文