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

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

问题描述

我正在为图书馆系统做一个手机缺口Android项目.我对移动应用程序开发不怎么了解.我正在使用MySQL创建数据库,并且需要在应用程序中填充HTML页面.我该怎么做?我什至不知道如何开始连接到外部数据库.而且我想在db中显示现有值,并希望从应用程序中添加新值.

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.

因此,正如我之前所说,如果您想与远程服务器通信 您将必须使用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.

您的方法应该是:

服务器端:

使用服务器端语言创建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 Web服务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");
    }
});

}

我认为这至少是一个开始.

I assume it will be at least a kick start.

希望有帮助.

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

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