connecting to an external database with phonegap-android app

十年热恋 提交于 2019-12-17 19:02:00

问题


I am doing a phone gap-android project for a library system. I don't have much idea about mobile application development. I am using MySQL to create the database and need to populate HTML pages in my application. How can I do it? I have no idea even how to start connecting to an external database. And I want to display existing values in db as well as want to add new values from application.


回答1:


Your app will reside on a device(android/iOS). So it will be a client side, more like a browser.

And you have communicate to server for getting or posting data.

You must be aware of that, phonegap use jQuery and javascript.

So as I told earlier, if you want to communicate with remote server you will have to call web services in your app using javascript.

Your approach should be:

Server Side:

Create the web services using your server side language.

Assuming you are using PHP as a server side language. Refer following links

  1. Creating PHP web services Tutorial
  2. Creating PHP web services PPT

Client Side:

Then you can use $ajax to fetch data from server or post data to server.

As far as $ajax call concerns, check out the following sample code.

function FetchData() {
$.ajax({
    async: false,
    type: "GET",
    url: "Your_WebService_URL",
    dataType: "json",
    success: function(data, textStatus, jqXHR) {
        $.each(data, function(i, object) {
            alert(obj.Data);
            //Here you can implement your client side logic.
        });
    },
    error: function() {
        alert("There was an error loading the feed");
    }
});

}

I assume it will be at least a kick start.

Hope that helps.



来源:https://stackoverflow.com/questions/17690111/connecting-to-an-external-database-with-phonegap-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!