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

查看:35
本文介绍了使用 phonegap-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.

您的方法应该是:

服务器端:

使用您的服务器端语言创建网络服务.

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 网络服务教程
  2. 创建 PHP 网络服务 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天全站免登陆