Twitter: raymondcamden

Address: Lafayette, LA, USA

Converting a dynamic web site to a PhoneGap application

Earlier today a reader asked me about the possibility of converting his mobile-friendly site into a "real" application via PhoneGap. I told him that this could be very easy. You can take your HTML, upload it to the PhoneGap Builder service, and see what you get. This works with simple HTML sites, but is not going to work well with dynamic sites built with server-side languages. In this blog post, I'll explain why it won't work, and also walk you through an example of converting a (simple) dynamic web site into a PhoneGap application.

Before I begin - two quick notes. I'll be using jQuery Mobile for the UI and ColdFusion for the back-end. This is completely inconsequential to the task at hand. Ok, ready?

First, let's discuss why a dynamic web site can't be simply converted as is into a PhoneGap application. Most of my readers are web developers so you should know this, but when it comes to dynamic server-side languages like ColdFusion, PHP, Ruby, etc, the HTML your browser gets is created dynamically.

Take for example this simple ColdFusion site. When you request this URL with your browser, my web server hands off the request to ColdFusion. ColdFusion does its magic (hits the database) and outputs raw HTML. That HTML is returned to the browser and rendered as is. The same would apply for PHP, Ruby, etc. When you click on the detail page, we hit one template that is passed a URL parameter that instructs the code to load a particular record and display it.

Now - consider PhoneGap. PhoneGap takes your HTML files and packages them up into a native application for your mobile platform. But it is not a web server. You can't bundle in ColdFusion or PHP and have it execute server-side code like in the example above.

Does this mean you're completely out of luck? Not at all. Let's look at how we can convert our code into a PhoneGap application.

First, let's look at the initial application. As I said above, the choice of the server-side language isn't relevant to the discussion. Therefore, I won't go into detail about what the ColdFusion code is doing. Those of you who don't know ColdFusion should be able to mentally map it to the language of your choice. First - the index page.

Then the detail page:

And finally - here is the component that drives the data. Basically it just wraps up the logic to get our list and detail.

Ok - so that's our old school (although nicely mobile optimized) web site. To begin the conversion to PhoneGap, I create a new file for my home page that is pure HTML, no ColdFusion.

Notice that the layout is the same as before, but our content is gone. Previously that was sourced on the server by a database call. So how do we add this dynamic data back in? With JavaScript.

First - let's add some logic to run when the home page is created. This specific event is based on how jQuery Mobile does things, but again, you could do this without any particular UI framework.

This code block performs a HTTP request to our server. (Note: I'm using localhost in the example above but in a real application it would be your site's domain, I've built a new set of server-side code just to handle getting and returning data in JSON format. So there's still a server involved, but now it's simply returning data, nothing more. I loop over the result and render it out into the page.

The detail page is built much like the index page. It's a copy of the earlier version minus any code or actual content.

To handle this, back in my JavaScript I added code to run when the page is loaded.

And that - as they say - is basically it. To summarize:

  • The code in the PhoneGap application is just HTML and JavaScript.
  • The dynamic data from the earlier application was rewritten to expose itself remotely.
  • PhoneGap then simply uses Ajax to fetch that data.

I've attached a zip of all the code used for this blog post below. If any part of this doesn't make sense, let me know, and I hope this was helpful.

Download attached file


  • Commented on 05-05-2012 at 12:09 PM
    Thank you Raymond, excellent tutorial.

    I have not yet tried PhoneGap but been wanting to. Your tutorial has peaked my interest.

    Can one use PHP files with PhoneGap, or does it have to be HTML files? Like to use some includes for a project in mind.

    Thanks again Raymond, great share.

  • Commented on 05-05-2012 at 12:29 PM
    Has to be HTML files... PhoneGap can't understand any server-side languages (PHP, ColdFusion, ASP, etc)
  • Commented on 05-05-2012 at 12:30 PM
    "Can one use PHP files with PhoneGap, or does it have to be HTML files?"

    Well, shoot, that was kind of the major point. :) If I didn't make that clear, I apologize. So no - you cannot. It has to be HTML.

    To be anal, you can use .txt, .xml, .csv, if you want to use JavaScript to parse them. The point is - you can't use a platform like PHP/CF within the PhoneGap app itself. Rather, you would use it via a network call.

  • Mikel #
    Commented on 05-05-2012 at 8:30 PM
    This is such a handy example! Thanks a lot for taking the time to put this together. I'm sure that many will find it very useful.

    I'm giving a small PhoneGap presentation at work this Friday and I already have several of your pages bookmark to share with the group. Well, now I have to add this one too :)
  • Don Vawter #
    Commented on 05-06-2012 at 12:04 PM
    I don't believe this example will fly on a device because it relies on localhost to serve the page and there will be no localhost cf server on the device. One would have to reference a remote cfserver. That is easily done. The only gotcha is that you have to remember to whitelist the url in phonegap. As a side note you don't have to worry about cross domain ajax calls because the built in server on the device acts as a proxy for the requests.

    As a general practice I have moved away from using cf in my presentation pages even on desktop applications and use cf only as a data server. - Conversion to mobile becomes much simpler and imo javascript with jQuery is much better at presentation.
  • Commented on 05-06-2012 at 12:14 PM
    The localhost thing was just a demonstration. I used a full URL on purpose - and obviously (ok, maybe it wasn't ;) the host would change depending on your server. Should I add a note for that point above?
  • Don Vawter #
    Commented on 05-06-2012 at 12:38 PM
    @Ray. Might be a good idea. Once you understand how PhoneGap works it is obvious you can't use localhost but if one is just learning it may not be, especially since localhost may very well work in a simulator.
  • Commented on 05-06-2012 at 1:14 PM
    Added a small note. Let me know if you think it helps.
  • Don Vawter #
    Commented on 05-06-2012 at 2:40 PM
    @Ray I think the note will help. Appreciate your responsiveness.
  • Commented on 05-06-2012 at 2:49 PM
    Sorry to ask such a stupid question. Should have been clear that HTML could not be used. Last time I will visit using a tablet that does not show code correctly.

    I will refrain from such in the future.
  • Commented on 05-06-2012 at 2:51 PM
    Terry, I hope I didn't sound too hard in my response. If so, I apologize. I have a fix for showing code in the mobile version, but I've yet to deploy it to my server. I'm going to do so Monday.
  • Commented on 05-06-2012 at 2:57 PM
    Terry (et all) - I felt bad about this - so I pushed the fix up. For folks curious, it is based on this blog entry:
  • Commented on 05-07-2012 at 9:37 AM
    It seems like this is a situation where a Javascript templating library like Handlebars would come in handy: it would simply be a matter of including the templating library in the PhoneGap project, wouldn't it (or are there issues with doing that)?
  • Commented on 05-07-2012 at 9:41 AM
    Brian - I'd say it depends. I specifically didn't go deep into the JS because the blog post was more about the conversion. The topic of how to actually build it will be depend on your JS skills, what libraries you like, etc.

    That being said - I freaking love Handlebars - and yes - it works on mobile. :)
  • Patrick Whittingham #
    Commented on 05-07-2012 at 10:29 AM

    I think you can use 'server-side' code in a PhoneGap application for both Android and Apple. This example will point to code on a web server

    Here is an example for Android.

    package com.test.test8t;

    import com.phonegap.*;
    import android.os.Bundle;

    public class test8T_srvActivity extends DroidGap {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
    super.setBooleanProperty("loadInWebView", true);
    super.setIntegerProperty("loadUrlTimeoutValue", 80000);
  • Commented on 05-07-2012 at 10:37 AM
    I see that as a solution, but most people I know doing PhoneGap do not do it that way. Also, this would have zero support for offline mode. Admittedly, so would using Ajax to fetch the data, but you could at least handle it better, switch to a local db for backup data, etc. But yea - that is an option.
  • Mark Gregory #
    Commented on 05-07-2012 at 7:36 PM
    Forgive the noobish question, but do Phone Gap apps run in Webkit, or do they get compiled to native code. I am at the starting line here, and considering Phone Gap versus Titanium (, which is a sort of metered service it appears.
  • Commented on 05-07-2012 at 8:10 PM
    It runs in a webkit browser run via native code. It's like a thin wrapper of deliciousness around the browser.
  • Mark Gregory #
    Commented on 05-07-2012 at 8:14 PM
    Ahh I see! Seeing as it runs from webkit, does it give access to hardware goodies like cameras, GPS, acceleromator, etc?

    (Pretty sure I spelled that accelerator part wrong!)
  • Commented on 05-07-2012 at 8:19 PM
    Absolutely - check the docs for an example. Here's a recorded Intro preso:

    Also, tomorrow, Andrew Trice and I are doing an open preso you can attend.
  • Mark Gregory #
    Commented on 05-07-2012 at 11:26 PM
    Ah Crikey! What am I waiting for?!?!
    Thank you sir!
  • Ali #
    Commented on 06-03-2012 at 11:32 AM
    Thank you. What would be your approach if it the site is a little more complicated. Maybe with login and logout, and user based views etc.
  • Commented on 06-03-2012 at 12:54 PM
    There's a couple things to consider here.

    1) Login is certainly possible. Its just one more Ajax call. If your back end supports cookie-based sessions, then your PG app's Ajax calls will pass those cookies back in future calls. That means your back end code could ensure a session exists (and has a verified login) before returning any data.

    2) User based views: Your login method could return a hashmap of allowed views, or roles, that your client app would use to render stuff. Obviously your back end code still needs to do validation, based on the session info.
  • Kulbhushan #
    Commented on 06-18-2012 at 8:34 AM
    Hello Ray,

    We are in the process of creating a PhoneGap application and the functionality would also be accessible from the mobile browser.

    We are having a discussion as to which option to use:
    1) Send json from server and keep html pages in the phonegap app.
    2) Send hrml pages populated with data to the phonegap app.

    The advantages we see are:
    1) Fixing bugs is easier, it is server side instead of getting the app certified all over again
    2) Probably more re use of code.

    Do you have any comments on this?
  • Commented on 06-18-2012 at 7:59 PM
    When you mention the advantages, I'm not sure which option you are speaking of. To me, you get more reuse if your server-side application is already using MVC. Your PG app can hit the model via a service layer and reuse the same business logic.
  • Phil Baumert #
    Commented on 06-28-2012 at 11:18 AM
    Hi, thanks for this super useful blog! I have this working on my application but I just want to have a different index page with a button to link to a page(i call it "intList.html") with the code you have on this examples index.html. For some reason, it does not load the data unless it is on the index.html page. What am I missing here? Thanks for your help. This is my index.html that has a link to intList.html with code from your index.html.

    <!DOCTYPE html>

       <meta charset="utf-8">
       <meta name="viewport" content="width=device-width, initial-scale=1">
       <link rel="stylesheet" href="css/" />
       <script src="js/jquery-1.7.2.min.js"></script>
       <script src="js/"></script>
       <script src="js/main.js"></script>


    <div data-role="page" id="indexPage">

    <div data-role="header">
    <img src="css/images/ryprad_logo.jpg"></h1>


    <div data-role="content">
    <a href="intList.html">Shows</a><br><br>
    <div data-role="footer">


  • Phil Baumert #
    Commented on 06-28-2012 at 3:01 PM
    Hey there again. I figured out everything runs "through" the index.html file. It works now. Thanks again for this awesome example!
  • Shawn Puyear #
    Commented on 08-10-2012 at 9:36 AM
    Please forgive the noob question, but when I preview the app in a browser, v1 displays just fine but v2 just displays a page with header and footer and no content. I changed the service call to point to my local server. Did I forget to do something?
  • Commented on 08-10-2012 at 9:45 AM
    v2 depends on "deviceready" being fired by PhoneGap. You can't just run it in the browser. You could - if you want - run it and open your console and run startup() manually.
  • Shawn Puyear #
    Commented on 08-10-2012 at 10:02 AM
    Thank you. If I wanted to view it working in a browser, is there a different event to call?
  • Commented on 08-10-2012 at 10:16 AM
    It depends on your code. If your code says, when deviceready is fired, run X, then you want to run X.
  • Shawn Puyear #
    Commented on 08-23-2012 at 1:17 PM
    Ray. Thanks again for your help. I got the data to display in a browser but cannot, for the life of me, get it to display in the Android. I even tried adding a button on the page to call startup() with no luck in the emulator.

    Could you suggest a method to fire the event to call and return the data in the emulator?
  • Commented on 08-23-2012 at 3:39 PM
    Did you remember to include cordova.js?
  • joseph #
    Commented on 09-06-2012 at 5:29 AM
    Hi Raymond,

    I created a web site in PHP and I load it in a phone gap app using onload function and ajax. Now I want to call phonegap function from my code in server. For example I want to take a photo can I call that photo function in my app ?
  • Commented on 09-06-2012 at 7:55 AM
    What do you mean you 'load' it? Are you loading just data or something else?
  • Shawn Puyear #
    Commented on 09-18-2012 at 8:28 AM
    Ray: Sorry for the long post. I am still hitting a snag and hope you can help. I did include a version of cordova.js in my site. Below is my head tag set.

       <meta charset="utf-8">
       <meta name="viewport" content="width=device-width, initial-scale=1">
       <title>Art Lister</title>
       <link rel="stylesheet" href="css/" />
       <script src="js/jquery-1.7.2.min.js"></script>
       <script src="js/"></script>
    <script src="cordova-"></script>
       <script src="js/main.js"></script>


    To run you through my process, I did the following:
    1. In Dreamweaver, I created a new site
    2. I copied the files from your v2 folder into the new site
    3. I copied the artservice.cfc to my testing server and made sure it was accessible
    4. I change the cfc call in the index,html page to pint to the cfc on my testing server
    5. I built the app using the PhoneGap functionality built into Dreamweaver
    6. I launched the app from Dreamweaver in an Android Virtual Device that I previously created

    The app installs fine in the AVD and opens, just no data is displayed. Only the header and footer show.

    Any ideas why the data is not displayed? Thanks!
  • Commented on 09-18-2012 at 8:43 AM
    The browser (and PhoneGap) on your AVD cannot hit localhost - which I assume you are using. Well, it can, but localhost is local to the device, not your hardware. Try using instead, which should point to your local machine.
  • Shawn Puyear #
    Commented on 09-18-2012 at 9:17 AM
    I wish it were that simple. I actually have the cfc on an external test server that I access via IP.
  • Commented on 09-18-2012 at 9:19 AM
    Oh, well then it should just work. I'd suggest checking the console.
  • Shawn Puyear #
    Commented on 09-18-2012 at 9:35 AM
    That is what I figured. Thanks again for your help.
  • Rikesh Subedi #
    Commented on 10-10-2012 at 11:46 AM
    Hi Raymond,
    I'm new to coldfusion and I want to work on PhoneGap. I loaded all your files in a local host and tried to run V1/index.cfm but is shows an error "Datasource cfartgallery could not be found." May i know the reason please?
  • Commented on 10-10-2012 at 4:15 PM
    That's a sample database you can get when installing ColdFusion.
  • Rikesh Subedi #
    Commented on 10-14-2012 at 11:38 PM
    XMLHttpRequest cannot load http://localhost:8500/service/artservice.cfc?metho.... Origin null is not allowed by Access-Control-Allow-Origin.

    how to overcome this error
  • Commented on 10-15-2012 at 2:18 AM
    Are you using a browser or a PhoneGap app to test?
  • al #
    Commented on 11-02-2012 at 5:28 PM
    As part of ajax call, can phonegap get HTML with scripts to download and execute on the mobile device?
  • Commented on 11-03-2012 at 8:24 AM
    Written correctly, yes. Imagine your remote HTML/script has a block of code that looks like this:

    function foo() { alert('x'); }

    This cannot be added to the app when loaded in via Ajax. Instead, your code must be written as

    foo = function() { alert('x'); }
  • max rossi #
    Commented on 11-07-2012 at 5:33 PM
    hi raymond,
    I tried this example these days, I installed the android sdk, everything ok, but my cfc works if I call the method with returntype="string", but doesn't work with returntype="query". Unfortunately I have no errors from the debug. I call the cfc in the external server with help help please....thank you very much
  • Commented on 11-08-2012 at 7:05 AM
    I'd need more details. So for example, you say it doesn't work, but exactly how? In your code that handles the response, if you alert() the response, do you see anything? Also, have you tried jQuery's Ajax error handling?
  • max rossi #
    Commented on 11-08-2012 at 11:37 AM
    My response is alert(undefined)
    my cfc:

    <cffunction name="getfatture" access="remote" returntype="query" output="false">

    <cfquery datasource="#request.datasource#" name="sel_fatture">
    SELECT CT_Fatture.id_fattura, CT_Clienti.Societa      
    FROM CT_Fatture
       INNER JOIN CT_Clienti ON CT_Fatture.id_cliente = CT_Clienti.id_cliente

    <cfreturn sel_fatture>

    and script:

    $("#indexPage").live("pageinit", function() {
       console.log("Getting remote list");
       $.get(";, {}, function(res) {
          var s = "";
    for(var i=0; i<res.length; i++) {
             s+= "<li><a href='detail.html?id=" + res[i].id_fattura + "'>" + res[i].societa + "</a></li>";

    thank you
  • Commented on 11-08-2012 at 11:45 AM
    Woah - why do you have a document.ready block inside your get response? That makes no sense and won't work at all. Remove that and keep the alert line.
  • max rossi #
    Commented on 11-08-2012 at 4:08 PM
    ok, but I get the same answer: undefined
  • Commented on 11-08-2012 at 4:36 PM
    Don't alert res.length, just res.
  • max rossi #
    Commented on 11-08-2012 at 5:55 PM
    yeah, you're right, sorry, alert[object Object]

    if i use
    alert(JSON.stringify(res, null, 4));

    i get

    {"COLUMNS":["ID_FATTURA","SOCIETA"],"DATA":[[2,"Receptour Srl"],[3,"Contech Sas"],[4,"Receptour Srl"],[5,"Receptour Srl"],[6,"Zama World Visa"]]}

    thank you very very much
  • Commented on 11-08-2012 at 8:52 PM
    Ok, so as you can see, the structure of your data is different. You can't do .length on it. You have an object with 2 main properties, COLUMNS and DATA. COLUMNS is an array of column names. DATA is an array of arrays where each element is one row of data, and each element in THAT array maps to the same COLUMNS array.
  • Commented on 01-09-2013 at 1:34 PM
    Raymond, great post and extremely helpful. Question. My mobile site is JQM and codeigniter php. The entire site is php based from a file naming convention as well as functions within. What I'm trying to wrap my head around is do I need to create the "template" html files as you have done for each page that needs to be pulled, or can I simply create an index.html page that does an ajax call to index.php? currently, all views are generated back thru the index.php page. hope that makes sense.


  • Commented on 01-10-2013 at 2:06 PM
    @John: I'm afraid I don't understand your question. I've described this technique as generically as I can. It should be applicable to any dynamic language. I don't quite know what your codeigniter does so I can't really comment.
  • Commented on 02-14-2013 at 10:37 AM
    For much more complicated server side templates, retrieving json and recreating the display logic on the mobile device can be a real pain. Stuff like Handlebars is extremely limited, especially when you are used to powerful server side scripting languages such as Cold Fusion or Freemarker.

    I was thinking more along the lines of retrieving the actual HTML in stead of json content and inserting that dynamically. There are some issues to overcome at first glance:
    * you would have to create some generic way of handling form submissions that integrates nicely with your existing server side infrastructure.
    * returned templates shouldn't contain any script src references.
    * you need to deal with session timeouts gracefully
    * you would have to do all this and at the same time avoid the Apple AppStore police saying it's too "webby"

    Non of this seems major. Any thoughts on this?
  • Commented on 02-15-2013 at 5:43 AM
    I attended a session by a Twitter dev last year where he talked about doing much the same thing. They found that creating HTML on the client (from data) was a bit too slow for them so they moved more to generating the HTML server side. So yes - I don't think this is crazy at all and it may work better for you.
  • Zana #
    Commented on 04-24-2013 at 5:09 PM
    Hi Raymond. I have a question. I'm using phonegap to create a web app and when i want to browse dynamically to another page as you did, it doesn't work and what i get is that the page is not found. Example : bloc_adresse ='<li><a href="page.html" rel="external"> '+titre+'</a></li>'; works but
    var bloc_adresse ='<li><a href="page.html?id='+id+' "rel="external"> '+titre+'</a></li>'; doesn't work. Can you please tell me if you have any idea.
  • Commented on 04-24-2013 at 5:14 PM
    There was a bug w/ urls with query string in older Androids/PhoneGap. Are you running the latest PhoneGap on a somewhat newish Android?
  • Zana #
    Commented on 04-24-2013 at 5:58 PM
    I'm running CordovaWP7 2.4.0 i'm doing the app for windows phone.
  • Zana #
    Commented on 04-24-2013 at 6:01 PM
    I'm downloading the 2.6.0 to test. will tell you if it works.
  • Commented on 04-25-2013 at 8:31 AM
    Wait, why are you doing rel=external? You don't need/want that.
  • Commented on 05-09-2013 at 5:08 AM
    Hi Ray,
    One question is this .cfm will work in iphone too ??
    actually i have tried & the problem i got is, below code is written in index.html
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta HTTP-EQUIV="REFRESH" content="5; url=index.cfm">
    when i run my app i m getting an error like :
    Failed to load webpage with error: Frame load interrupted..
    Can you please help me ??
  • Commented on 05-10-2013 at 9:06 AM
    Kalgi, your question does not make any sense. My post isn't about making a CFM work on a mobile device. It is about how you would rewrite, or extend, an existing server-side app so you can use it from your mobile device with HTML and JS.
  • Jerry #
    Commented on 06-27-2013 at 10:08 AM
    I am a newbie to PhoneGap.
    Typically PhoneGap app start from a local HTML. How could the try to get other domain work?
  • Commented on 06-27-2013 at 12:57 PM
    You can't do that. Well technically you can - but Apple won't approve an app that just loads up the entire content from your site.
  • Rupesh Kumar #
    Commented on 07-22-2013 at 12:26 AM
    hey Raymond,

    with the help of your example (and few extra source). i'm using the following jquery mobile code to get json data
    type: "POST",
    url: ";,
    cache: false,
    dataType: "json",
    data: formData,
    success: onSuccess,
    error: onError

    function onSuccess(data, status)
              var output = $('#projectlist');
             var place = '';
              $.each(data, function(i,value){
       place += '<li><a href="">' + value.firstName + '<span class="ui-li-count">' +'</span></a></li>';



    my html has following code
    <div id="main-content" class="content" data-role="content">
             <ul id="projectlist" data-role="listview" data-filter="true" data-filter-placeholder="Search projects..." data-inset="true">

    i can make it run on browsers (chrome, safari, FF), but not on emulator or device. i have been struggling for 2 days. i'm using dreamweaver cs6 and phonegap.
  • Commented on 07-22-2013 at 6:43 AM
    You didn't say how it failed on the emulator/device. If you are using iOS, I recommend remote debugging with Safari to see if you can expose the error better.
  • rupesh kumar #
    Commented on 07-22-2013 at 7:23 AM
    please check this url: (you can view console (on chrome) to see json output.

    but when i run this on emulator (uploaded the screenshot on, it just shows the search box and no list view.

    i have changed the code since my last point

    updated jquery code:
    <link rel="stylesheet" href="; />
    <script src=""&g...;
    <script src=";

       $(document).on('pagebeforeshow', '#home', function(){
          $.getJSON(";, function(projects) {
             $.each(projects, function(i, projects){
          function generateProjectLink(projects){
             return '<li><a href="">' + projects.firstName + '<span class="ui-li-count">' +'</span></a></li>'

    my html has following code
    <div id="main-content" class="content" data-role="content">
    <ul id="projectlist" data-role="listview" data-filter="true" data-filter-placeholder="Search projects..." data-inset="true">


    i'm using dreamweaver cs6 and phonegap.

    i'm stuck big time :-(
  • Commented on 07-22-2013 at 8:42 AM
    Oh, you probably need to to your ACCESS element. Please see the PhoneGap docs on this.
  • Rupesh Kumar #
    Commented on 07-23-2013 at 12:18 AM
    thanks for your reply

    i added <access origin=""" target="_blank">"; /> to config.xml. is there any specific place to store it. i have this file in the config file looks like bellow

    ?xml version="1.0" encoding="UTF-8" ?>
    <widget xmlns = "";
    xmlns:gap = "";
    id = "com.phonegap.example"
    version = "1.0.0">

    <access origin=""" target="_blank">"; />

    Audit and Compliance

    <author href=""; email="">
    Rupesh Kumar


    but adding this also did not work. i hope i get a working example as per my json" target="_blank">
  • Commented on 07-23-2013 at 6:45 AM
    I replied via email as well, but I think your issue is the access value. Try changing origin to
  • Rupesh Kumar #
    Commented on 07-24-2013 at 5:39 AM
    thanks Raymond for your help. i have moved forward. but now i ran into another problem

    i have index.html file with following changePage function

    $.mobile.changePage( "show_projects.html", { transition: "slideup", changeHash: false });

    the problem is that when i run "show_projects.html" directly, it loads the data from json (perfect).

    but when i call index.html first and then use $.mobile.changePage( "show_projects.html", { transition: "slideup", changeHash: false }); "show_projects.html" does not load json, any idea? the jquery code on show_projects.html is

    $(document).on('pageinit', '#navigation', function(){ $.ajax({url: ";, dataType: "json", jsonpCallback: 'successCallback', async: true, beforeSend: function() { $.mobile.showPageLoadingMsg(true); }, complete: function() { $.mobile.hidePageLoadingMsg(); }, success: onSuccess, error: function (request,error) { alert('Network error has occurred please try again!'); } }); });
  • Commented on 07-24-2013 at 11:25 AM
    Is #navigation the page id for show_projects.html?
  • Mark #
    Commented on 08-08-2014 at 7:29 PM
    HI Raymond, very informative site. I'm trying to convert an application running on Coldfusion MX 7.0.2 into a mobile app. First thing I need to do I guess is be able to access my CF server code using javascript which brought me here.

    I can't get this example working at all. Just get a page with the headings, no data. I created a directory called mobile on my server account and uploaded the three directories (V1, V2, service) in the zip file. I ran the code <my domain>mobile/v1/index.html and just get the headings. If I look using firebug the cfc is generating a 500 server error. If I go directly to the cfc file in the browser with <my domain>mobile/service/artservice.cfc?method=getArtList I get the following error:

    "The method 'getArtList' could not be found in component WEB-INF.cftags.component. Check to ensure that the method is defined, and that it is spelled correctly."

    Any idea what's going wrong. Also is there a super simple example of accessing and displaying a CFQUERY from javascript. I figure if I can at least get that working it's a good first step. I've tried about every jquery, ajax sample on the web and I can't get any of them working. Some I can get the cfc working directly from the browser but then can't get the data to display in the HTML page. Very frustrating, any help appreciated.
  • Commented on 08-08-2014 at 7:41 PM
    Does the CFC have a method called getArtList?
  • Mark #
    Commented on 08-08-2014 at 8:52 PM
    No, I guess not. I picked up the example from browsing the web so I thought that the function name would equate to method, since.

    <cffunction name="get_all_users" access="remote" hint="Gets all users in the database" >
    could be accessed from the browser by /test.cfc?method=get_all_users

    remote array function getArtList() {
    could be accessed from the browser by /artservice.cfc?method=getArtList

    Apparently not, so not sure why the call from the index.html javascript in your example :
    and in my example

    is generating a 500 server error and how I can test the cfc directly.
  • Commented on 08-08-2014 at 9:15 PM
    Um, having some trouble parsing your comment. So... if the file is called artservice.cfc and the method in there is getallusers, then yes, you can hit it at your PATH HERE/artservice.cfc?method=getallusers.

    Maybe share your real URL so we can hit it and see.
  • Adrian #
    Commented on 09-02-2014 at 10:13 PM
    Hi Raymond!

    Thx for this interesting idea.

    I have a question: Is there any way for a webpage to call a PhoneGap app?
    I want to upload images taken with the device's (tablet, phone) camera.

    Have you heard about any way to do that?

    Have a great day!
  • Commented on 09-03-2014 at 6:13 AM
    The closest I can think of would be intents with Android. This article seems to cover the iOS way:

    Give those a shot first.

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty