gpt4 book ai didi

php - 来自 mysql 数据库的 ListView 结果

转载 作者:行者123 更新时间:2023-11-29 23:34:06 25 4
gpt4 key购买 nike

基于此主题:Changing the content of div in Jquery Mobile我想使用 php 和 json 从 mysql 表中检索数据,但此操作中没有显示任何内容。

以下是使用的信息:

json.php

$conexion = new mysqli("localhost", 'xxx', 'xxx', 'Operations');  

$query = "SELECT * FROM bugs";

$result = mysqli_query($conexion,$query);

while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {

$id['projectid'] = $row['projectid'];
$id['status'] = $row['status'];
$id['severity'] = $row['severity'];
$id['title'] = $row['title'];
$id['creation_date'] = $row['creation_date'];

array_push($result_array,$id);

}

echo json_encode($result_array);

index.html

<!DOCTYPE html> 
<html>
<head>
<title>Bugs Administration</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>
<script>
$(document).live('pageinit',function (event) {
$.ajax({
url: 'http://127.0.0.1/app/json.php',
data: "",
dataType: 'json',
success: function(data)
{
for (var i = 0; i < data.length; i++) {
$('#list').append("<li><b>Project ID: </b>"+ data[i].projectid +
"<b>Status: </b>"+ data[i].status+
"<b>Severity: </b>"+ data[i].severity+
"<b>Title: </b>"+ data[i].title+
"<b>Creation Date: </b>"+ data[i].creation_date+
"</li>");
}
$('#list').listview('refresh');

}
});
});
</script>
</head>
<body>
<div data-role="page" id="bugs">
<div data-role="header">
<h1>List of Bugs</h1>
</div><!-- /header -->
<div class="Main" data-role="content">
<h3>Current opened bugs</h3>
<ul data-role="listview" id="list"></ul>
</div><!-- /content -->
<div data-role="footer">
<h3>Mobile App</h3>
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>

实际上是这样的结果:

enter image description here

我做错了什么?

最佳答案

我认为这是一个跨域问题,如果您的index.html文件与您的json.php位于同一文件夹中,您可以尝试使用相对路径进行ajax调用吗?

$.ajax({
url: 'json.php',
data: "",
dataType: 'json',
success: function(data)
{
for (var i = 0; i < data.length; i++) {
$('#list').append("<li><b>Project ID: </b>"+ data[i].projectid +
"<b>Status: </b>"+ data[i].status+
"<b>Severity: </b>"+ data[i].severity+
"<b>Title: </b>"+ data[i].title+
"<b>Creation Date: </b>"+ data[i].creation_date+
"</li>");
}
$('#list').listview('refresh');

}
});

这是完整的index.html代码:

<!DOCTYPE html>
<html>
<head>
<title>Bugs Administration</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>
<script>
$(document).live('pageinit',function (event) {
$.ajax({
url: 'json.php',
data: "",
dataType: 'json',
success: function(data)
{
console.log(data);
for (var i = 0; i < data.length; i++) {
$('#list').append("<li><b>Project ID: </b>"+ data[i].projectid +
"<b>Status: </b>"+ data[i].status+
"<b>Severity: </b>"+ data[i].severity+
"<b>Title: </b>"+ data[i].title+
"<b>Creation Date: </b>"+ data[i].creation_date+
"</li>");
}
$('#list').listview('refresh');

}
});
});
</script>
</head>
<body>
<div data-role="page" id="bugs">
<div data-role="header">
<h1>List of Bugs</h1>
</div><!-- /header -->
<div class="Main" data-role="content">
<h3>Current opened bugs</h3>
<ul data-role="listview" id="list"></ul>
</div><!-- /content -->
<div data-role="footer">
<h3>Mobile App</h3>
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>

关于php - 来自 mysql 数据库的 ListView 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26443920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com