此刻,我正在创建一个PhoneGap应用程序,并且我一直在使用ajax在该应用程序的html页面中显示来自我的MySQL数据库的信息。如果我在PhoneGap外部运行HTML页面,它将显示该表,但它不在PhoneGap中,而且我不确定为什么我对PhoneGap和编码工作还是很陌生?
我的代码如下;
display.php:
<?php
include("connection.php");
mysqli_select_db($con, "mscim2018_lmm12");
$result=mysqli_query($con, "select * from food");
echo "<table border='1' >
<tr>
<td align=center> <b>Roll No</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Address</b></td>
<td align=center><b>Stream</b></td></td>
<td align=center><b>Status</b></td>";
while($data = mysqli_fetch_row($result))
{
echo "<tr>";
echo "<td align=center>$data[0]</td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center>$data[2]</td>";
echo "<td align=center>$data[3]</td>";
echo "<td align=center>$data[4]</td>";
echo "</tr>";
}
echo "</table>";
?>
connection.php:
<?php
$con=mysqli_connect("--","--","--");
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
?>
(正在使用framework7,因此没有HTML标记,但是脚本是在索引文件中准确地提供的)food.html;
<div class="navbar">
<div class="navbar-inner">
<div class="left">
<a href="index.html" class="back link">
<i class="icon icon-back"></i>
<span>Back</span>
</a>
</div>
<div align="center" class="center sliding"><strong>CFPal - BMR</strong></div>
<div class="right">
<a href="#" class="link icon-only open-panel"><i class="icon icon-bars"></i></a>
</div>
</div>
</div>
<div class="pages" align="center">
<div data-page="about" class="page" align="center">
<div class="page-content">
<div class="content-block" id="bmipage">
<h3 align="center">Manage Student Details</h3>
<table border="1" align="center">
<tr>
<td> <input type="button" id="display" value="Display All Data" /> </td>
</tr>
</table>
<div id="responsecontainer" align="center">
</div>
</div>
</div>
</div>
</div>
和ajax.js:
$(document).ready(function() {
$("#display").click(function() {
$.ajax({ //create an ajax request to display.php
type: "GET",
url: "https://cs1.ucc.ie/~lmm12/ProjectTraining/display.php",
dataType: "html", //expect html to be returned
success: function(response){
$("#responsecontainer").html(response);
//alert(response);
}
});
});
});