我有一个用 HTML/Javascript 编写的网站,我使用 jquery 通过调用 php 文件从 MYSQL 加载数据。该网站正在运行。我正在尝试对同一个网站进行phonegap,但MySQL 中的数据未加载。我没有在数据库连接中使用本地主机。我的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>
最佳答案
尝试获取这样的数据
var table_data = $.parseJSON($.ajax({
type: "post",
url: SITE_URL,
dataType: "json",
async: false
}).responseText);
然后运行以下代码
$.each(table_data, function(index, item) { })
希望它适合你
关于Javascript不加载mysql数据phonegap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43190294/