Use of Jquery

You must Login before you can answer or comment on any questions.

Hi, I had a native iPhone App calling an RSS and showing data plus Details in native datagrid. All I had used was jquery.jgfeed and jquery.js. My app was completed in less then 100 lines of code in less then two hours. How do I do the same with the 0.9.x and 1.0 SDK? I have spend more then few days just to figure out where to start from! The whole idea of using titanium is that I do not have to learn anything new. I have been working with jquery for quite some time now and I know all the AJAX, JSON and other APIs on top of my head, do I have to start learning new XHR apis of titanium now? What is the best way to port my app from older sdk to newer one? I have already seen But please please please do not remve jquery support.

11 Answers

Accepted Answer

You can actually use jQuery if you declare empty variables before including the library. Obviously i don't think it is possible or neccessary to use the DOM - functions but utilitys work just fine.

Just prefix the library with something similar to this, i used an older jquery library because this seems to work in 1.3.2:

var window = {}; var document = { getElementById: function(){}, createComment: function(){}, documentElement: { insertBefore: function(){}, removeChild: function(){} }, createElement: function(elm){ return obj = { innerHTML: '', appendChild: function(){}, getElementsByTagName: function(){ return {}; }, style: {} },


}; var navigator = { userAgent: "" }; var location = { href: '' };

Have fun trying this out.

Re the question of whether jQuery 1.4 is supported: you can use basically any JS library you want in a WebView. Outside of a WebView, you can use basically any JS library that does not require the DOM (like json2.js, etc.)

Re the larger point: Libraries like jQuery which assume there is a "document" object (and "navigator", etc. -- those things available in a web browser) will not function outside of a WebView in Titanium Mobile SDK 1.0.

Personally, I wouldn't think this to be so much of a deal breaker. I would think the trade-off is totally one-sided in favor of moving to 1.0: massive improvements in native compatibility and performance, versus needing to write a few lines of your own AJAX code using the built-in Titanium.Network.HTTPClient. Is it really so hard to replace the $.ajax shortcuts that jQuery provides? The "biggest" part an ajax call is writing the callback function -- something you need to do in that $.ajax call as well as when using HTTPClient.

On the other hand, if it is a deal breaker, you can put everything in a WebView and thereby continue the model that was used in 0.8.x. But be sure to watch Kevin's video (he mentions it above) because some things have changed, like you can't create native controls on the WebView.

Or you can stick with 1.0 and look for a third-party ajax library that doesn't rely on the DOM, like jx -- of course you'd still need to change your code, but it might be simpler than writing all your own AJAX handling.

jQuery is still supported in web views, so if you'd like to develop using mostly web technologies that's cool with us. It's just going to be a little different in 1.0, since we want to empower real native apps moreso than "native web pages".

I did a webinar on moving from 0.8 to 1.0 which is available online here:

@Clint Tredway How can we import jQuery.js in app.js? Before I used to use tag in a webview to do that and then used to write native controls in that webview. I have seen some include api but they do not work in including external js.

Can I still choose to use Jquery/JqueryUI and not include any extra titanium stuff?

This is problem for all of us who have developed apps using JQuery to make AJAX calls in 0.8. Is all that work rendered useless in 0.9? This has got to be a dealbreaker for a lot of guys. Personally, this was what made it so attractive to me.

This should still be usable. Are any of you getting errors when trying it? is not working? If its not, post some code and we will try to reproduce it.

KitchenSink 1.0.x on github has jquery 1.3.2 included. Does Titanium Mobile support jquery 1.4.x ?

@Bill Dawson <br/> Well you are right, the advantages are so higher that we will keep using the native way, I also used Titanium.Network.HTTPClient and it was not many lines of code as well. Only thing is it took me some time to find and learn it. Anyways, I have started using the native APIs and things should go pretty swiftly.

This thread is old but the most popular when I do any search online. So I'll post my query here (haha!). Is the jQuery library included with Appcelerator natively supported in Mobile now? Can I include jQuery 'DOM' and utility commands and expect them to perform? Cheers!

That's what I want to clarify, I do not want to build web pages, I want to create native apps but while I do that there are smaller tasks like making AJAX calls or executing.getJSON or using for-each loops which comes in pretty handy for example I had following code $.ajax({ type: "POST", url: "PersonService.asmx/GetPerson", data: "some=data", dataType: "json", success: function(JSONObj) { //create native data grid using JSONObj here
} });

Can I still use the code above to populate a native grid?

Your Answer

Think you can help? Login to answer this question!