你好,我有一个php页面,通过ajax请求媒体使用div输出我的html页面中的结果,
我打算使用listviews来推广这个结果,因为我的应用程序针对手机和平板电脑,所以我正在使用jquery移动框架。
我已成功使用此
输出结果 <?php header('Access-Control-Allow-Origin: *'); ?>
<?php
$users = ($_GET['users']);
$user = ($_GET['user']);
$con = mysqli_connect('localhost','whitech3_manage','famakin','whitech3_manage');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"whitech3_manage");
$sql="SELECT * FROM data WHERE fromwhere = '".$users."' and towhere = '".$user."'";
$result = mysqli_query($con,$sql);
echo '<head>';
echo "<link rel='stylesheet' href='themes/transport.min.css' />";
echo "<link rel='stylesheet' href='themes/jquery.mobile.icons.min.css' />";
echo "<link rel='stylesheet' href='themes/jquery.mobile.structure-1.4.2.min.css' />";
echo "<script src='themes/jquery-1.10.2.min.js'></script>";
echo "<script src='themes/jquery.mobile-1.4.2.min.js'></script>";
echo '</head>';
while($row = mysqli_fetch_array($result)) {
echo "<div data-role='collapsible' data-theme='b' data-content-theme='b'>";
echo "<ul data-role='listview' data-filter='true'>";
echo "<li><a href='#'>". $row['fromwhere'] . "</a></li>";
echo "<li><a href='#'>". $row['towhere'] . "</a></li>";
echo "<li><a href='#'>". $row['details'] . "</a></li>";
echo "<li><a href='#'>". $row['time frame'] . "</a></li>";
echo "</ul>";
echo "</div>";
}
mysqli_close($con);
?>
但是每当我的结果显示时,他们都没有正确格式化,看起来像列表视图,因此我知道我应该加载我的样式表和javascript标签,以确保列表视图正确显示。
我已经尝试过并使用echo语句来回显我的样式表和js的链接,但它似乎让我的listview正确显示。
这是我试过的
echo '<head>';
echo "<link rel='stylesheet' href='themes/transport.min.css' />";
echo "<link rel='stylesheet' href='themes/jquery.mobile.icons.min.css' />";
echo "<link rel='stylesheet' href='themes/jquery.mobile.structure-1.4.2.min.css' />";
echo "<script src='themes/jquery-1.10.2.min.js'></script>";
echo "<script src='themes/jquery.mobile-1.4.2.min.js'></script>";
echo '</head>';
function showUser() {
if (showUser == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
var usersvalue=encodeURIComponent(document.getElementById("users").value)
var uservalue=encodeURIComponent(document.getElementById("user").value)
xmlhttp.open("GET","http://whitechapelandpartners.com/getuserwrong.php?users="+usersvalue+"&user="+uservalue, true);
xmlhttp.send();
}
}
<div id="txtHint"><b>Person info will be listed here.</b></div><br /><br /><br /><br />
</div>
任何建议请按照逻辑我希望echo语句能够正常工作
答案 0 :(得分:0)
试试这个:
function showUser() {
if (showUser == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var collapsible = xmlhttp.responseText;
document.getElementById("txtHint").innerHTML = $(collapsible).collapsible();
}
}
var usersvalue=encodeURIComponent(document.getElementById("users").value)
var uservalue=encodeURIComponent(document.getElementById("user").value)
xmlhttp.open("GET","http://whitechapelandpartners.com/getuserwrong.php?users="+usersvalue+"&user="+uservalue, true);
xmlhttp.send();
}
}
<div id="txtHint"><b>Person info will be listed here.</b></div><br /><br /><br /><br />
</div>
我希望这有效。 :d
答案 1 :(得分:0)
这是我的建议
<?php header('Access-Control-Allow-Origin: *'); ?>
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='themes/transport.min.css' />
<link rel='stylesheet' href='themes/jquery.mobile.icons.min.css' />
<link rel='stylesheet' href='themes/jquery.mobile.structure-1.4.2.min.css' />
<script type="text/javascript" src='themes/jquery-1.10.2.min.js'></script>
<script type="text/javascript" src='themes/jquery.mobile-1.4.2.min.js'></script>
<script type="text/javascript">
function showUser(user) { // how do you call this? You need to pass it a user too
if (user == "") {
$("#txtHint").empty();
return;
}
var usersvalue=encodeURIComponent($"#users").val()),
uservalue=encodeURIComponent($("#user").val());
// assuming you are accessing the same origin
$.get("/getuserwrong.php?users="+usersvalue+"&user="+uservalue,
function(data) {
$("#txtHint").html(data);
}
);
}
</script>
</head>
<body>
<?php
$users = ($_GET['users']);
$user = ($_GET['user']);
// I think you do not want to show your userID and password here on this site
$con = mysqli_connect('localhost','...','...','...');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"whitech3_manage");
$sql="SELECT * FROM data WHERE fromwhere = '".$users."' and towhere = '".$user."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo <<<EOT
<div data-role='collapsible' data-theme='b' data-content-theme='b'>
<ul data-role='listview' data-filter='true'>
<li><a href='#'>$row['fromwhere']</a></li>
<li><a href='#'>$row['towhere']</a></li>
<li><a href='#'>$row['details']</a></li>
<li><a href='#'>$row['time frame']</a></li>
</ul>
</div>
EOT;
}
mysqli_close($con);
?>
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>