我明白在這個特定主題上有很多帖子,但似乎沒有解決我的特定問題。JQuery沒有收到POST請求的結果
我使用jQuery的post方法來查詢數據庫中的值,該值等於輸入框中的文本。返回的結果應該顯示在下面的文本輸入框中。但由於某些原因,發佈請求的成功條件從未執行。從邏輯上說,這表明我的發佈請求或發佈的PHP文件中都有錯誤,所以我將粘貼這裏的代碼。
jQuery的
$(document).ready(function() {
$('#title').change(function() {
var data = 'title='+$(this).val();
$.post('getinfo.php', data, function(response){
if(response.toString() == 'invalid')
{
alert('no such book title');
}
else
{
alert('book found');
}
});
return false; // required to not open the page when form is submited
});
});
的獲得info.php的文件
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$title = $_post['title'];
$db = loader::db();
$res = $db -> Execute('select isbn from btBookList where title = ?', array($title));
if($res !=null)
{
$identifier = '';
foreach($res as $row)
{
$identifier = $row['isbn'];
}
echo json_encode($identifier);
}
else
echo 'invalid';
?>
這是用混凝土5,因此在參數的defined('C5_EXECUTE') or die(_("Access Denied."));
和
$db = loader::db();
$res = $db -> Execute('select isbn from btBookList where title = ?', array($title));
您允許通過標題帖子變量進行sql注入。我相信你的問題是與你的文章的數據部分。 – abc123
你是在本地訪問你的jQuery文件,還是通過Web服務器? (即使它在本地託管)..基本上,地址欄中的URL是以「http」還是「文件」開頭?如果是後者,則可能遇到跨域策略文件錯誤(http://en.wikipedia.org/wiki/Same_origin_policy) – Alfie
當沒有匹配的行時會發生什麼? $ res實際上是否爲空或它是一個空數組? 您是否嘗試過使用Chrome,Safari或Firefox開發人員工具檢查/從您getinfo.php頁面的網絡請求/響應? – SnowInferno