Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery not loading on the iPhone

I'm trying to use a UIWebView to display content, and jQuery to manipulate that content, but I can't get jQuery to load. Here's the code that I have setting up the UIWebView, setting the baseURL, and loading the content (an HTML file that's in the local bundle):

UIWebView *view = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];

NSData *htmlData = [[NSData alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]]];
NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[view loadHTMLString:htmlString baseURL:baseURL];

The content loads just fine, and I've confirmed that the baseURL is correct by adding an image to the bundle and referencing it in the HTML, and it works. Using the same HTML in Safari on my Macbook jQuery is loading just fine, too, and working as expected.

I've tried both using the compressed jquery-1.3.2.min.js and the development jquery-1.3.2.js, and no dice for either.

Any ideas?

like image 449
John Biesnecker Avatar asked Apr 27 '09 08:04

John Biesnecker


2 Answers

Gah! EBCAK!

Turns out when I copied the jquery javascript source into the project, it was copied into the target's "Compile Sources," which of course threw errors. I deleted it from "Compile Sources" but didn't add it back to "Copy Bundle Resources."

/me slaps forehead repeatedly.

like image 189
John Biesnecker Avatar answered Oct 24 '22 01:10

John Biesnecker


Have you tried copying both the .html and .js files to the app's documents folder, and pointing the UIWebView to that local folder?

like image 37
Alex Reynolds Avatar answered Oct 24 '22 00:10

Alex Reynolds