mugetsu
mugetsu

Reputation: 4408

ajax code works in android, fails on iOS

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");
});

Upvotes: 2

Views: 1110

Answers (2)

Titouan de Bailleul
Titouan de Bailleul

Reputation: 12959

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

Upvotes: 2

Deric
Deric

Reputation: 21

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

Upvotes: 2

Related Questions