Returning Dynamic Content In A PhoneGap App

This is probably known to many but I was looking into this for fellow co-workers and I figured I would blog it so I don't forget it in the future. PhoneGap is great at making an HTML page into an mobile application. The thing with HTML is, it's static. You can't do direct database calls on load. Here is a quick solution I have found that seems to work. If other's have found a better solution, please post it.

index.html

view plain print about
1<!doctype html>
2<html>
3    <head>
4        <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
5        <title>My App</title>
6        <script src="phonegap.js" type="text/javascript" charset="utf-8"></script>
7        <script src="jquery.js" type="text/javascript" charset="utf-8"></script>
8        
9        <script type="text/javascript">
10            jQuery(document).ready(function() {
11                $.ajax({
12                    url:"http://www.ryanvikander.com/test.cfc?method=getdata",
13                    success: function(data){
14                        var content = $("#content");
15                        
16                        content.html(data);
17                    },
18                    error: function(e){
19                        console.log(e);
20                    }
21                });
22            });
23        </script>
24
25    </head>
26    <body>
27         <div id="title_bar">Test</div>
28        This is a test
29        <div id="content"></div>
30    </body>
31</html>

So really all I am doing is making a call to a cfc on load that returns some content and then adds that content to a div. Pretty simple.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
# Posted By Tony Nelson | 3/28/12 7:12 PM
Ryan Vikander's Gravatar Yes that works too, I just like using Ajax.
# Posted By Ryan Vikander | 3/28/12 7:13 PM
Phil Baumert's Gravatar Hello. What does the .cfc file look like?
# Posted By Phil Baumert | 6/22/12 6:38 PM
John's Gravatar This is cool and all, but why not just do a meta tag refresh to your site's real page? Does phone gap prevent that or something?
# Posted By John | 8/4/12 10:35 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.6.004. Contact Blog Owner