连接到外部数据库与phonegap-android应用程序 [英] connecting to an external databse with phonegap-android app

查看:95
本文介绍了连接到外部数据库与phonegap-android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为图书馆系统做手机差距android项目。我不太了解移动应用程序开发。我使用MySQL创建数据库,并需要在我的应用程序中填充HTML页面。我该怎么办呢?我不知道如何开始连接到外部数据库。

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.

推荐答案

您的应用程序将驻留在您的应用程序上一个设备(android / iOS)。
所以它将是一个客户端,更像一个浏览器。

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.

你必须知道,phonegap使用jQuery和javascript。

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

正如我先前所说,如果你想与远程通信server
您必须使用javascript在您的应用程序中调用web服务。

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.

您的方法应该是

服务器端

使用服务器端语言创建Web服务。

Create the web services using your server side language.

假设您使用 PHP 作为服务器端语言。
请参阅以下链接

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


  1. 创建PHP Web服务教程

  2. 创建PHP网络服务PPT

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

客户端

然后,您可以使用 $ ajax 从服务器
获取数据或将数据发送到服务器。

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

至于 $ ajax 调用问题,请查看以下示例代码。

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");
    }
});

}

希望有所帮助。

这篇关于连接到外部数据库与phonegap-android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆