我正在尝试从 mysql 数据库中显示 html 列表。要从 mysql 获取数据,我正在使用 json 和 javascript。但它什么也没显示!
我的html页面是
<!DOCTYPE html>
<html class="ui-mobile-rendering">
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/jquery.mobile-1.0.1.min.css"/>
</head>
<body>
<div id="tenant" data-role="page">
<div data-role="header">
<a href="index.html" data-icon="back" class="back ui-btn-left">Back</a>
<h1>My Lease</h1>
</div>
<div data-role="content">
<ul id="actionList" data-role="listview" data-inset="true">
</ul>
</div>
</div>
<script src="js/tenantlease.js"></script>
<script src="lib/jquery-1.7.1.min.js"></script>
<script src="js/jqm-config.js"></script>
<script src="lib/jquery.mobile-1.0.1.min.js"></script>
<script src="lib/underscore-min.js"></script>
<script src="lib/backbone-min.js"></script>
<script src="js/main.js"></script>
</body>
</html>
我的 php 文件是。当我从带有 id 的浏览器调用时,它工作正常。
<?php
session_start();
include 'connection.php';
$email=$_SESSION["PM"];
$sql = "select * from phpap105_tenantinfo where TenantEmailAddress=:id";
try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare($sql);
$stmt->bindParam("id", $_GET[id]);
$stmt->execute();
$employee = $stmt->fetchObject();
$dbh = null;
echo '{"item":'. json_encode($employee) .'}';
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
?>
我的 javascript 文件是
$('#tenant').live('pageshow', function(event) {
//var id = getUrlVars()["id"];
var id = 'mukul_kuet@yahoo.com';
$.getJSON('tenantlease.php?id='+id, displayEmployee);
});
function displayEmployee(data) {
var employee = data.item;
//console.log(employee);
if (employee.TenantFirstName) {
$('#actionList').append('<li><h3>First Name</h3>' +
'<p>' + employee.TenantFirstName + '</p></a></li>');
}
if (employee.TenantLeaseSigned) {
$('#actionList').append('<li><h3>Lease Sign</h3>' +
'<p>' + employee.TenantLeaseSigned + '</p></a></li>');
}
$('#actionList').listview('refresh');
}
请帮助我如何在 html 页面中获取数据。在此先感谢您的任何帮助。