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, something.com.) 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.
Archived Comments
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.
Terry
Has to be HTML files... PhoneGap can't understand any server-side languages (PHP, ColdFusion, ASP, etc)
"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.
Clearer?
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 :)
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.
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?
@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.
Added a small note. Let me know if you think it helps.
@Ray I think the note will help. Appreciate your responsiveness.
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.
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.
Terry (et all) - I felt bad about this - so I pushed the fix up. For folks curious, it is based on this blog entry:
http://www.raymondcamden.co...
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)?
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. :)
Raymond,
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. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setBooleanProperty("loadInWebView", true);
super.setIntegerProperty("loadUrlTimeoutValue", 80000);
super.loadUrl(
"https://www.test_server/apps/folder1/www/index.html");
}
}
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.
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 (http://www.appcelerator.com/), which is a sort of metered service it appears.
It runs in a webkit browser run via native code. It's like a thin wrapper of deliciousness around the browser.
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!)
Absolutely - check the docs for an example. Here's a recorded Intro preso: http://www.raymondcamden.co...
Also, tomorrow, Andrew Trice and I are doing an open preso you can attend.
Ah Crikey! What am I waiting for?!?!
Thank you sir!
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.
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.
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?
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.
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>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RYP</title>
<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.mobile-1.1.0.min.js"></script>
<script src="js/main.js"></script>
</head>
<body>
<div data-role="page" id="indexPage">
<div data-role="header">
<h1>Shows</h1>
<img src="css/images/ryprad_logo.jpg"></h1>
</div>
<br><br><br>
<div data-role="content">
<a href="intList.html">Shows</a><br><br>
</div>
<br><br><br>
<div data-role="footer">
<h4>Stat</h4>
</div>
</div>
</body>
</html>
Hey there again. I figured out everything runs "through" the index.html file. It works now. Thanks again for this awesome example!
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?
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.
Thank you. If I wanted to view it working in a browser, is there a different event to call?
It depends on your code. If your code says, when deviceready is fired, run X, then you want to run X.
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?
Did you remember to include cordova.js?
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 ?
What do you mean you 'load' it? Are you loading just data or something else?
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.
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Art Lister</title>
<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.mobile-1.1.0.min.js"></script>
<script src="cordova-2.0.0.0.js"></script>
<script src="js/main.js"></script>
</head>
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!
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 10.0.0.2 instead, which should point to your local machine.
I wish it were that simple. I actually have the cfc on an external test server that I access via IP.
Oh, well then it should just work. I'd suggest checking the console. http://www.raymondcamden.co...
That is what I figured. Thanks again for your help.
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?
That's a sample database you can get when installing ColdFusion.
XMLHttpRequest cannot load http://localhost:8500/service/artservice.cfc?method=getArtList&returnformat=json. Origin null is not allowed by Access-Control-Allow-Origin.
how to overcome this error
Are you using a browser or a PhoneGap app to test?
As part of ajax call, can phonegap get HTML with scripts to download and execute on the mobile device?
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'); }
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 cf8....help help help please....thank you very much
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?
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
</cfquery>
<cfreturn sel_fatture>
</cffunction>
and script:
<script>
$("#indexPage").live("pageinit", function() {
console.log("Getting remote list");
$.mobile.showPageLoadingMsg();
$.get("http://invoice.contechnet.i...", {}, function(res) {
$(document).ready(function(){
alert(res.length);
});
$.mobile.hidePageLoadingMsg();
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>";
}
$("#artList").html(s);
$("#artList").listview("refresh");
},"json");
});
</script>
thank you
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.
ok, but I get the same answer: undefined
Don't alert res.length, just res.
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
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.
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.
regards,
John
@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.
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?
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.
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.
There was a bug w/ urls with query string in older Androids/PhoneGap. Are you running the latest PhoneGap on a somewhat newish Android?
I'm running CordovaWP7 2.4.0 i'm doing the app for windows phone.
I'm downloading the 2.6.0 to test. will tell you if it works.
Wait, why are you doing rel=external? You don't need/want that.
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
<body>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta HTTP-EQUIV="REFRESH" content="5; url=index.cfm">
</body>
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 ??
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.
I am a newbie to PhoneGap.
Typically PhoneGap app start from a local HTML. How could the try to get other domain work?
$.get("http://anotherdomain/..."...)
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.
hey Raymond,
with the help of your example (and few extra source). i'm using the following jquery mobile code to get json data
$.ajax({
type: "POST",
url: "http://projects.corewebconn...",
cache: false,
dataType: "json",
data: formData,
success: onSuccess,
error: onError
});
function onSuccess(data, status)
{
var output = $('#projectlist');
var place = '';
output.empty();
$.each(data, function(i,value){
place += '<li><a href="">' + value.firstName + '<span class="ui-li-count">' + value.id+'</span></a></li>';
});
$("#projectlist").html(place);
$("#projectlist").listview("refresh");
//console.log(data);
}
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">
</ul>
</div>
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.
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.
please check this url: http://www.qhse-riskapplica... (you can view console (on chrome) to see json output.
but when i run this on emulator (uploaded the screenshot on http://www.qhse-riskapplica..., 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="http://code.jquery.com/mobi..." />
<script src="http://code.jquery.com/jque..."></script>
<script src="http://code.jquery.com/mobi..."></script>
<script>
$(document).on('pagebeforeshow', '#home', function(){
$.getJSON("http://www.qhse-riskapplica...", function(projects) {
$("#projectlist").empty();
$.each(projects, function(i, projects){
$("#projectlist").append(generateProjectLink(projects));
console.log(generateProjectLink(projects));
//alert(projects.firstName);
});
$("#projectlist").listview("refresh");
});
function generateProjectLink(projects){
return '<li><a href="">' + projects.firstName + '<span class="ui-li-count">' + projects.id+'</span></a></li>'
}
});
</script>
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">
</ul>
</div>
i'm using dreamweaver cs6 and phonegap.
i'm stuck big time :-(
Oh, you probably need to addprojects.corewebconnecti... to your ACCESS element. Please see the PhoneGap docs on this.
http://docs.phonegap.com/en...
thanks for your reply
i added <access origin="http://www.qhse-riskapplica..." /> to config.xml. is there any specific place to store it. i have this file in http://www.qhse-riskapplica.... the config file looks like bellow
?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.phonegap.example"
version = "1.0.0">
<name>Audit</name>
<access origin="http://www.qhse-riskapplica..." />
<description>
Audit and Compliance
</description>
<author href="https://www.domain.com" email="you@domain.com">
Rupesh Kumar
</author>
</widget>
but adding this also did not work. i hope i get a working example as per my json
http://www.qhse-riskapplica...
I replied via email as well, but I think your issue is the access value. Try changing origin to qhse-riskapplications.com.
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: "http://projects.domain.com/...", 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!'); } }); });
Is #navigation the page id for show_projects.html?
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.
Does the CFC have a method called getArtList?
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.
test.cfc
<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
that
artservice.cfc
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 :
http://localhost/testingzone/phonegaptests/conversion/service/artservice.cfc?method=getArtList&returnformat=json
and in my example
http://www.mydomain.com/mob...
is generating a 500 server error and how I can test the cfc directly.
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 domain.com/ANY PATH HERE/artservice.cfc?method=getallusers.
Maybe share your real URL so we can hit it and see.
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!
The closest I can think of would be intents with Android. This article seems to cover the iOS way: http://iosdevelopertips.com...
Give those a shot first.
Is there a recommended way to store the external urls we hit through the Phonegap app. Do we use the config.xml for it ? I tried Google but didnt get any specific answers
Sorry, what external URLs?
i am new in phonegap.
I can't import this in my eclipse ... what can i do .......???
You do not need to use Eclipse to do PhoneGap. It sounds like you need some more basic education about PG - I'd suggest the docs or picking up my book (still in early access): http://www.manning.com/camden/
Hi Raymond, Thank you for the excellent tutorial. I was wondering if I can package just the landing index.html (lets make it a login page) page along with all css and js files into phonegap app. from there on, once the user logs in can we fetch data directly from the other files located on webserver and display inside the app?
How do I go about doing this?
This is exactly what my post is talking about. Or am I misreading your question?
Hi Raymond,
I just learnt about phonegap. Does it mean it will be far more easier to convert to phonegap if i have the existing web app that mostly written in front end js framework like knockout js or angular js? And is phonegap app identical to single page application?
Thank you your article really helps me understanding the phonegap.
-Markus
"Does it mean it will be far more easier to convert to phonegap if i have the existing web app that mostly written in front end js framework like knockout js or angular js?" Yes - that would help.
"And is phonegap app identical to single page application?" Not necessarily. PhoneGap/Cordova describes how you convert your HTML/JS/CSS to a mobile app. It does NOT tell you how to write your code. So a PhoneGap/Cordova app *may* be a SPA or not. It is certainly recommended, but not required.
hi Raymond,
I am an electrical engineer and my thesis for my msc is about a smart home using arduino and all of this to be handled by an android smartphone. I have written the code which is actually an html including xml-ajax-javascript. The only problem is that i don't know how to convert all of those an android app. I can send you my code if you are willing to help.
Thanks in advance,
-Petros
It sounds like you are asking how to build a hybrid app in general. If so, I'd go to http://cordova.apache.org and start learning about Apache Cordova. You can also buy my book - it is on sale from my About page.
Hi!! :) Can I use this to call my wordpress page? So I can controlled the content in my CMS without having to write anything in phone-gap, just this script to call the web?
Also, is this can be used as the page warp, I can add the Push Notification Page to it? For example, I send a push, and they all be on an app tabs, where I can see all notifications listed? Or PG just let you send notifications and you can't see a list of notifications you have received on your device on this particular app?
You can point to an external site, but if your phone goes offline than nothing will work.
I'm sorry - but your second paragraph makes no sense to me.
Hi,
Is it possible to convert a JQuery + PHP + Mysql web site to an application without minimum rework ?
Tkx !
Honestly it depends on your app.
can I build if I just use index.php ? not using index.html
I'm not sure what you mean. In this article, I'm discussing how to convert a dynamic site to one for PG - the technology is ColdFusion, but that is secondary to the general guidelines. It would apply to Node, PHP, .Net, etc. If you're asking if you can follow the same guide for a PHP site, well then sure, and if anything made you think you couldn't, let me know and I'll clear it up in the article.
i have a wordpress self hosted website, can you write tutorial for it?
Not really. I explained the process in general here. It should get you started in the right direction.
ok thx. i just found a wp plugin for phonegap called appkit. i successfully built my app. https://uploads.disquscdn.c...
Grats. :)
Download attachment link broke!
Link fixed.
Ray
Thanks for the link fix.
Just now starting to work with the phonegap. I have tried to play with your code but am stumped. I feel that its a brain cramp but the data from the cfc is returned as
{"COLUMNS":["FIELD_MST_MLS_NUMBER"],"DATA":[[95938],[101048],[115971],[109493],[109860]]}
I can see the columns console.log(res.COLUMNS.length) ; returns 1
console.log(res.COLUMNS) ; returns ["FIELD_MST_MLS_NUMBER"]
For the life of me I cannot get to the DATA.
Manny
It is under res, so res.DATA. The result is an array of arrays, where the item in [0][0] represents the first row, and first col, which for you is FIELD_MST_MLS_NUMBER.
I did not give you credit back a few months ago. Thanks that work for me!!
Manny
No worries - glad it helped.
Ray,
I have a web application built in C#, implementing ASP.NET. The front-end consists of .NET Razor (.cshtml extension) instead of regular HTML and javascript. I am curious as to how to convert such an application to mobile with PhoneGap. Will I need to completely overhaul the Razor Views into plain HTML and then re-write the logic with javascript? I appreciate your article and any clarification you may provide.
Thank you,
Jim
Without knowing what Razor Views are I'd have to say yes. At the end, they have to present "normal" HTML/JS to the browser, so *that* is what you have to work with, not Razor.