简体   繁体   English

将HTML5 PhoneGap App连接到在线数据库

[英]Connect HTML5 PhoneGap App to an online database

I am looking to make an HTML 5 App which will be available on the apple and android store. 我正在寻找一个HTML 5应用程序,它将在苹果和Android商店提供。 (so it needs to be cross platform and for which I am using Phonegap) (所以它需要跨平台,我正在使用Phonegap)

My problem is the information displayed on the app will be updated regularly via some online database that will be edited online by myself not users. 我的问题是应用程序上显示的信息将通过一些在线数据库定期更新,该数据库将由我自己在线编辑而非用户。 What is the best practice to connect to this database and what database would work best (note the information isn't private and can be openly available the information is used to populate lists and content on the app) 连接到此数据库的最佳做法是什么,以及哪种数据库最有效(请注意,该信息不是私有的,可以公开获取,该信息用于填充应用中的列表和内容)

I have been looking into XML then JSON for the "database" and handlebars to insert the content, which I've gone off a bit.. 我一直在寻找XML然后JSON为“数据库”和把手插入内容,我已经走了一点..

Think of this as an HTML5 app that has to use js. 可以把它想象成一个必须使用js的HTML5应用程序。 The app itself is simple it's just classified lists ( category , genre , list , item ) and then a title:img:description of each item. 应用程序本身很简单它只是分类列表( categorygenrelistitem ),然后是title:img:description每个项目的title:img:description

Any help, code or insight would be great. 任何帮助,代码或见解都会很棒。 Thanks for your time! 谢谢你的时间!

You can use any database of your choice on the server side. 您可以在服务器端使用您选择的任何数据库。 Suppose your database is on mysql then you can write some php script to retrieve the data. 假设您的数据库在mysql那么您可以编写一些PHP脚本来检索数据。 Next these php scripts should return some kind of JSON or XML response based on your choice. 接下来,这些php脚本应根据您的选择返回某种JSON或XML响应。 Lastly you can use ajax to call those php scripts and get those JSON / XML response inside your app and extract them. 最后,您可以使用ajax调用这些PHP脚本,并在您的应用程序中获取这些JSON / XML响应并将其解压缩。

Now there are many many ways. 现在有很多方法。 You should use in which you are comfortable with. 你应该使用你感到舒服的。 So many database options so many scripting language options. 如此多的数据库选项有如此多的脚本语言选项。

Search -> analyze -> try -> use 搜索 - >分析 - >尝试 - >使用

Get familiar with AJAX calls to server. 熟悉对服务器的AJAX调用。

You will get some idea from this link 你会从这个链接中得到一些想法

An example: 一个例子:

PHP script: PHP脚本:

<?php
include("dbconfig.inc.php");
header("Content-type: text/xml");

echo "<?xml version=\"1.0\" ?>\n";
echo "<Loadinglist>\n";


    $select="Select * FROM tb_table";
    $dbh->query("SET NAMES utf8;");
    $dbh->query("SET CHARACTER_SET utf8;");


        foreach($dbh->query($select) as $row)
        {
            echo "<bangla>\n";

            $id=$row['id'];
            echo "\t<id>"."<![CDATA[".$id."]]>"."</id>\n";


            $category=$row['category'];
            echo "\t<category>"."<![CDATA[".$category."]]>"."</category>\n";


        }



echo "</Loadinglist>";
?>

Sample ajax call 示例ajax调用

jQuery.ajax({
                                  url: 'http://www.examplecom/myscript.php',  //load data 
                                  global: false,
                                  type: "POST",
                                  dataType: "xml",
                                  data: data,
                                  async: true,
                                  timeout: 40000,
                                  success: loading_complete_list,
                                  error: errorfunc
                            });

Search them, learn them, try them. 搜索它们,学习它们,尝试它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM