LJ Wilson
LJ Wilson

Reputation: 14427

UIWebView not causing document.ready to fire

I have a simple application that does nothing more than load an NSURLRequest in a UIWebView. If I load this either using the simulator or on a device, the jQuery method $(document).ready doesn't fire. I have created a test page to verify this:

https://dl.dropbox.com/u/3660978/webviewtest.html

Here is the code that loads up the WebView:

-(void)loadWebView {
    NSURL *url = [NSURL URLWithString:@"https://dl.dropbox.com/u/3660978/webviewtest.html"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
}

#pragma mark - WebView Delegate Method
-(void)webViewDidFinishLoad:(UIWebView *)webView {
    NSLog(@"WebView is done loading");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadWebView];
}

If I load this up using the Safari app on my iPad, it works fine (I get two alerts), whenever I run the app using either the simulator or that same iPad it fails to call $(document).ready (I only get the first alert).

I have tried using both iOS 5 and iOS 6.1 simulators. What gives?

Upvotes: 2

Views: 1150

Answers (1)

Richard Brown
Richard Brown

Reputation: 11444

The path you have for jQuery isn't complete. In your dropbox it begins: // instead of http://, so jQuery doesn't load, hence the call for document.ready (which is in jQuery) doesn't run.

The alternative is to embed the jQuery library in the bundle and reference it locally.

Upvotes: 1

Related Questions