【问题标题】:Javascript not loading mysql data phonegapJavascript没有加载mysql数据phonegap
【发布时间】:2017-08-28 15:41:47
【问题描述】:

我有一个用 HTML/Javascript 编写的网站,我使用 jquery 通过调用 php 文件从 MYSQL 加载数据。该网站正在运行。我正在尝试调用同一个网站,但未加载来自 MySQL 的数据。我没有在数据库连接中使用 localhost。我的 jquery 有问题吗?

<!-- Ajax for JSON -->
<script src="dist/js/jquery-1.12.4.min.js"></script>

<div id="featured_items" class="streamline message-box message-nicescroll-bar">
    <script type='text/javascript'>
       $(document).ready(function () {
          /* call the php that has the php array which is json_encoded */
          $.getJSON('php/items.php', function (get_items) {
          /* data will hold the php array as a javascript object */
          $.each(get_items, function (get_items_key, get_items_val) {
             $("#featured_items").append(
                '//HTML Code Here'
             );
          });
       });
    });
    </script>
</div>

【问题讨论】:

  • 您的地址错误,您需要一个完整的服务器 URL,例如 example.com/php/items.php
  • example.com 没有 http 没有工作,甚至破坏了工作网站。带有 http 的 example.com/php/items.php 确实在网站上工作,但没有解决无法在 phonegap 中加载的数据。

标签: javascript php jquery mysql cordova


【解决方案1】:

尝试获取这样的数据

var table_data = $.parseJSON($.ajax({
    type: "post",
url: SITE_URL,
dataType: "json",
    async: false
}).responseText);

然后运行以下代码

$.each(table_data, function(index, item) { })

希望对你有用

【讨论】:

  • 我用过它并在网站上测试过,现在它是空白的。也许是我在 php 文件中的 Json 编码?
  • 请确认您在SITE_URL 变量和您的php 文件中写入了正确的url,得到输出后您已经写入echo json_encode($result);
猜你喜欢
  • 2011-03-18
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多