제발 도와주세요, 정말 미쳐 버릴거야!.텍스트 상자에 삽입 된 값을 기준으로 동적 드롭 다운을 채 웁니다.
몇 가지 질문이있는 PHP 양식이 있는데 질문 중 하나는 "어느 영화를 좋아합니까?"입니다. 내가 잘 작동 jQuery 자동 완성 기능을 사용! 그러나 사용자가 영화의 이름을 잊어 버릴 수도 있지만 해당 영화에서 연기 한 배우를 기억할 수도 있습니다. 그래서 자동 완성 텍스트 상자 (예 : "Tom Cruise")에서 배우/여배우 이름을 입력 할 수있게하고 삽입 된 액터 이름을 기준으로 액터가 나열된 동영상 목록이 포함 된 동적 드롭 다운 메뉴를 추가해야합니다. (예 : Tom Cruise)가 그들과 함께했습니다. ((
<html>
<?php
print_r($_POST);
?>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"/>
</head>
<body>
<input type="textbox" name= "tag" id="tags">
<select id="movieImdbId" name="movieImdbId[]" multiple="multiple" width="200px" size="10px" style=display:none;>
</select>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
<script type="text/javascript">
$(document).ready(function() {
$("#tags").autocomplete({
source: "actorsauto.php", //php file which fetch actors name from DB
minLength: 2,
select: function (event, ui){
var selectedVal = $(this).val(); //this will be your selected value from autocomplete
// Here goes your ajax call.
$.post("actions.php", {q: selectedVal}, function (response){
// response variable above will contain the option tags.
$("#movieImdbId").html(response).show();
});
}
});
});
</script>
</body>
</html>
이것은 actions.php입니다 :
이
내가 시도했지만 작동하지 않을 것입니다<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_GET['q']) && !empty($_GET['q'])){
$q = $_GET['q'];
include('Connection.php'); //connection to the DB
$sql = $conn->prepare("SELECT DISTINCT movieImdbId FROM movie_roleNames WHERE castName = :q");
$sql->execute(array(':q' => $q));
$html = "";
while($row = $sql->fetch(PDO::FETCH_OBJ)){
$option = '<option value="' . $row->movieImdbId . '">' . $row->movieImdbId . '</option>';
$html .= $option;
}
echo $html; // <-- this $html will end up receiving inside that `response` variable in the `$.post` ajax call.
exit;
}
?>
질문 : 사용자가 텍스트에서 배우의 이름을 삽입하는 이유 -box를 선택하면 드롭 다운 메뉴가 채워 지지만 은 EMPTY입니까?
PHP에서 데이터가 성공적으로 반환되고 있습니까? – tymeJV
@tymeJV : html/js 파일의 시작 부분에'print_r ($ _ POST);'라고 쓰고, localhost에 보이는 것은 Array()입니다. 그래서 생각합니다. 그것은 빈 배열을 반환합니다 ... – mOna