Fyrebend
Fyrebend

Reputation: 133

Html cloud storage?

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?

Upvotes: 1

Views: 1416

Answers (2)

Prashant G
Prashant G

Reputation: 4900

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:

Upvotes: 1

enigma
enigma

Reputation: 3491

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.

Upvotes: 0

Related Questions