用戶需要點擊演員列表中的演員。現有的電影標題將被刪除,然後只會顯示與所選演員相關的電影標題。Json在我的列表框中獲取「未定義」值
在選擇演員後,我的「dvdtitle」列表框會收到「未定義」列表。不過,我檢查json_encode
功能與$('#actor').text(data)
響應數據,以獲得它的視覺,我確實得到正確。
[{"503":"Caught In The Crossfire"},
{"690":"Dead Man Running"},
{"1064":"Get Rich Or Die Trying"},
{"1145":"Gun"},{"1254":"Home of The Brave"},
{"2184":"Righteous Kill"},
{"2519":"Streets Of Blood"},
{"3273":"Twelve"}]
我不知道我在做什麼錯。
//getactors.php
include("includes/connection.php");
$q = $_POST['input'];
$final_array = array();
$resultActor = mysql_query("SELECT id, title, plot, catagory, release_date, rated FROM dvd WHERE actors LIKE '%".$q."%' ");
while($rowActor = mysql_fetch_array($resultActor)) {
$final_array [] = array($rowActor['id'] => $rowActor['title']);
}
echo json_encode($final_array);
// JavaScript Document
$('#actorsname').click(function(){
var actorValue = $('#actorsname option:selected').text();
$.ajax({
type: "POST",
url: 'getactors.php',
data: {input: actorValue},
cache: false,
datatype: "json",
success: function(data) {
$('#dvdtitle option').each(function(i, option) {
$(option).remove(); // Empty DVD Listbox
});
$('#actor').text(data); // to visualy check my json Data
$.each(data, function(i, j) {
var row = "<option value=\"" + i.value + "\">" + j.text + "</option>";
$(row).appendTo("select#dvdtitle");
});
}
});
});
您的查詢容易受到[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)的影響。 – paislee
你正在要求一個屬性'價值'我是當前元素的索引不是對象 – Dalen
@Dalen,準備向佩斯利解釋它應該如何幫助。 – mowwwalker