gpt4 book ai didi

php - 你如何将 php 结果填充到 jquery 移动 ListView 中

转载 作者:行者123 更新时间:2023-12-04 20:33:37 25 4
gpt4 key购买 nike

我有我的 php,下面是我的 html 代码。我试图用 php 代码填充 ListView 但失败了,任何想法

<?
require_once("../backend/functions.php");
dbconn();

$id = $CURUSER["id"];
$e = date("Y/m/d");
$a = SQL_Query_exec("SELECT enddate FROM cal_events WHERE userid = '$id'
AND enddate > '$e' ORDER BY enddate ASC");

if (mysql_num_rows($a) == 0) {
?>
<script>
alert("You have no active events to deal with");
window.location ='index.html';
</script>

<?
}else{

$data = array();
while($rowa = mysql_fetch_array($a))
{
$data[] = $rowa;
}
echo json_encode($data);
}

现在我的 html 不正确,这是我在正确方向上需要一点帮助的地方

html

<script type="text/javascript">
$(document).on("pagebeforeshow", "#index4", function() {
$(function(){
var items="";
$.getJSON("check-events.php",function(data){
$.each(data,function(index,item)
{
items+="<li>"+item.enddate+"</li>";
});
$("#contacts").html(items);
$("#contacts").trigger("change");
});
});
});
</script>
<ul id="contacts" data-role="listview" data-divider-theme="b" data-inset="true">
</ul>

我哪里错了?它确实填充了列表,但没有 jquery 元素

最佳答案

你的 php 文件返回 json 但你应该添加

header('Content-Type: application/json');

在回显你的 json 之前

关于php - 你如何将 php 结果填充到 jquery 移动 ListView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16083372/

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