将数据库添加到jquery移动站点

我很擅长使用jquery和jquery mobile,但我想知道是否有一种简单的方法(或者教程最好)将数据库(远程和本地)绑定到jquery移动站点(最好不使用php)。

您可以通过JavaScript使用HTML5 localStorage,这是一个解释和教程的一些链接: http : //www.html5rocks.com/en/features/storage

…现在有几种技术允许应用程序在客户端设备上保存数据……

如果您想与服务器进行交互,那么您将需要使用服务器端脚本语言。 使用AJAX与服务器通信相当容易:

JS–

//run the following code whenever a new pseudo-page is created $(document).delegate('[data-role="page"]', 'pagecreate', function () { //cache this page for later use (inside the AJAX function) var $this = $(this); //make an AJAX call to your PHP script $.getJSON('path_to/server/script.php', function (response) { //create a variable to hold the parsed output from the server var output = []; //if the PHP script returned a success if (response.status == 'success') { //iterate through the response rows for (var key in response.items) { //add each response row to the output variable output.push('
  • ' + response.items[key] + '
  • '); } //if the PHP script returned an error } else { //output an error message output.push('
  • No Data Found
  • '); } //append the output to the `data-role="content"` div on this page as a listview and trigger the `create` event on its parent to style the listview $this.children('[data-role="content"]').append('
      ' + output.join('') + '
    ').trigger('create'); }); });

    PHP–

      0) { //iterate through the results of your query while ($row = mysql_fetch_assoc($query)) { //add the results of your query to the output variable $output[] = $row; } //send your output to the browser encoded in the JSON format echo json_encode(array('status' => 'success', 'items' => $output)); } else { //if no records were found in the database then output an error message encoded in the JSON format echo json_encode(array('status' => 'error', 'items' => $output)); } ?> 

    您还可以将数据发送到PHP脚本并将其添加到数据库中。

    以下是上面使用的函数的一些文档页面:

    jQuery .getJSON() : http : .getJSON()

    PHP json_encode() : http : json_encode()

    使用http://westcoastlogic.com/lawnchair/
    它提供了许多存储方式,您可以按顺序放置所有适配器(如何存储的选项),以便它可以获取浏览器上可用的第一个适配器。 它也使用JSON格式,无论你是否想使用localstorage或sqlite,所以你只需要处理JSON数据。

    如果你想要一个数据库,那么移动浏览器中的SQLLite就会以Web SQL数据库的forms得到广泛支持,目前大多数Android和iPhone设备都支持这种数据库 。

    要查看工作示例,请检查以下链接:

    http://desalasworks.com/html5-databases-on-iphone/

    请注意,SQLLite中可用的SQL语言比(我假设的)MySQL数据库更受限制。 您可以创建/删除表,选择,插入和更新,但会丢失一些更高级的操作。