我有一個ibook,我試圖從我的服務器雲中的數據庫中取回數據表。如果我將main.html文件放在我的服務器上並使用我的Web瀏覽器瀏覽它,它就像一個返回數據表的champ,但是當我將這個html作爲main.html文件放入Info.plist中時,它不會在ibook中顯示錶格。我錯過了什麼?如何讓ibook顯示從在線數據庫查詢的數據
這裏是我的html文件,該文件是在iBook的HTML插件的插件的書
<html>
<head>
<script type="text/javascript" src="http://myserver.com/ibook_widgets/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: 'post',
url: 'http://myserver.com/ibook_widgets/getdata.php?id=4',
data: 'json',
beforeSend: function() {
// before send the request, displays a "Loading..." messaj in the element where the server response will be placed
$('#resp').html('Loading...');
},
timeout: 10000, // sets timeout for the request (10 seconds)
error: function(xhr, status, error) { alert('Error: '+ xhr.status+ ' - '+ error); },
success: function(response) { $('#listhere').html(response); }
});
});
</script>
</head>
<body>
<div id="listhere" style="border: solid black 1px; background-color:red;">Replace this text with html table from php file</div>
</body>
</html>
這裏的網頁是我的PHP文件,該文件是我的服務器上
<?php
/*
* Following code will list all the products
*/
$dbhostname='myserver.com';
$dbusername='usr';
$dbpassword='pwd';
$dbname='mydatabase';
$con = mysql_connect($dbhostname,$dbusername,$dbpassword);
mysql_select_db($dbname, $con);
// check for post data
if (isset($_POST["id"]))
{
$inValue = $_POST['id'];
$sql = 'select id, btn_txt from mytable where parent_id = '.$inValue.' order by btn_txt';
$result = mysql_query($sql) or die(mysql_error());
if (!empty($result))
{
// check for empty result
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array($result);
$btntxt = $row['btn_txt'];
$result1 = mysql_query($sql) or die(mysql_error());
// check for empty result
if (!empty($result1))
{
// check for empty result
if (mysql_num_rows($result1) > 0)
{
// looping through all results
// products node
$tmpStr = "<table border='1'><tr><th>Tap A Row To See Details</th></tr>";
// show select box input_select_4
while($row1 = mysql_fetch_array($result1))
{
$tmpStr = $tmpStr . "<tr><th><a href=\"http://myserver.com/ibook_widgets/getdata.php?id=". $row1["id"] . "\" target=\"_self\">" . $row1["btn_txt"] . "</a></th></tr>";
}
$tmpStr = $tmpStr . "</table>";
echo $tmpStr;
// echoing JSON response
///echo json_encode($tmpStr);
mysql_close($con);
// echoing JSON response
////echo json_encode($response);
}
}
}
}
}
?>
什麼我錯過了嗎?
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – thaJeztah
你的代碼對於SQL注入來說很脆弱,在你的SQL語句中使用它們之前,你沒有*轉義值,這可能導致敏感信息和數據丟失。閱讀本網站的一些例子,並可能發生什麼:http://www.unixwiz.net/techtips/sql-injection.html – thaJeztah
謝謝你的答覆...這兩個都是有效的意見,但不是問題的答案我問......我最終發現了這個問題......如下所述,它與CORS有關。 –