1

I'm trying to make an app using phonegap, but what I want to know is if it is possible to store information online. For example, say there is a number variable, and it is added to when a button is pushed. Could that value be saved somewhere and then a totally different device can retrieve the variable?

I looked at databases, but I couldn't really understand it. I want something that can be accessed by any device as long as It has a key or something.

Is this possible? If so, how would I do it?

Fyrebend
  • 123
  • 2
  • 2
  • 9
  • This is possible, you may want to change your title though as you currently word it I am not sure that it makes sense. What you want is a centralized database that each of your client apps can call out to and do CRUD. In addition to this, you may also want to look into the pubsub architecture depending on your needs. – dkroy Apr 17 '15 at 21:38
  • So what should I change the title to? – Fyrebend Apr 17 '15 at 21:40
  • You could have the form submitting to a PHP page somewhere. That's how I would do it. – Slava Knyazev Apr 17 '15 at 21:42
  • 1
    This is kind of a broad question. In short, the answer is Yes and how depends on what you use for storage. Server with SQL or MySQL or something like Firebase, etc. Not sure if your going to get a 'good' answer to your question. – Kalel Wade Apr 17 '15 at 21:42
  • Well I just need a direction to go...I don't know where to start, so any help wOuld give me direction – Fyrebend Apr 17 '15 at 21:43
  • Potentially similar question: http://stackoverflow.com/questions/13899702/phonegap-application-that-communicate-with-a-remote-db – dkroy Apr 17 '15 at 21:44
  • 1
    This is simply too broad. Yes, you can do this. This is how a large chunk of the web works...data is stored on a server that you can access from anywhere. There's no real one place to start short of googling. – DA. Apr 17 '15 at 21:54
  • IMO - You really should try again... concentrate on learning databases. I cannot stress how important it will be to work with them in the future. Also as @KalelWade mentioned above, Firebase can lead you in the right direction (there are tons of tutorials with Phonegap + Firebase). – dannypaz Apr 17 '15 at 21:55

2 Answers2

1

PhoneGap uses JS so you cannot connect to the database directly. You should create a Web service using server side languages like PHP on external server and make ajax request on your web service. This approach is possible using PhoneGap.

Sample Code will look somewhere near:

function FetchData() {
$.ajax({
    async: false,
    type: "GET",
    url: "Your_WebService_URL",
    dataType: "json",
    success: function(data) {
        $.each(data, function(i, object) {
            if(i==="title"){
                document.getElementById("title").InnerHTML = object;
            }
            if(i==="home_image"){
                document.getElementById("title").InnerHTML = '<img src="'+object+'"/>';
            }

        });
    },
    error: function() {
        alert("There was an error loading the feed");
    }
});

The web service, in this case json will throw the variables. May me somewhere like this :

[{"title":"my application"},{"home_image":"http://link.com/image.png"}]

I think this article is useful to you: Loading external data into a PhoneGap app using the jQuery JSONP plugin for cross-domain access. Also see this similar question here:

Community
  • 1
  • 1
Prashant Ghimire
  • 4,890
  • 3
  • 35
  • 46
0

This is entirely possible.

You essentially need two components: the client interface, and the server.

The client displays the results to the users, and, using your example, waits for a button to be pushed. On the push of that button, the client would send a request to the server to increment the stored value (possibly through a jQuery.post, or get, function call).

The server page, written in php for example, receives this request, and accesses a file, or more realistically a database, to increment the value.

With some Googling, this should be very doable, but post specific questions if you get stuck.

Community
  • 1
  • 1
enigma
  • 3,476
  • 2
  • 17
  • 30
  • 1
    This seems doable. Thank you very much. I will mark this as the answer, because it's giving me what to look for. Do you also know how to set up a server? – Fyrebend Apr 17 '15 at 21:54
  • @firebend77 Look into services like Firebase that do all the server work for you, until you are ready/willing to tackle that challenge too. – dannypaz Apr 17 '15 at 21:59
  • So can firebase connect with phonegap? If so, that may be the way I go. – Fyrebend Apr 17 '15 at 22:00
  • I remember trying it before, but I was confused. I'll try it again and Google but if I get really stuck I'll be asking for help on connecting to the db – Fyrebend Apr 17 '15 at 22:01
  • @firebend77 During the development stage, I find setting up a server on my local machine to be extremely useful. A tool such as [XAMPP](https://www.apachefriends.org/index.html) does a lot of the hard work for you, and sets up an apache server with php and a database right out of the box – enigma Apr 17 '15 at 22:13
  • @firebend77 As for phonegap, I found it most useful to get a web app working in my browser first, and then put it into phonegap, assuming it doesn't make use of too many phone-only APIs. That might just be a personal preference, but it made the process faster (for me). – enigma Apr 17 '15 at 22:17