사용자가 jQuery 자동 완성 상자에서 활동 (예 : 영화 또는 합기도 시청)을 선택할 수있는 응용 프로그램이 있습니다. 그 부분이 효과가 있습니다. 그러나 내가 원하는 것은 전문 지식이 관련이없는 경우 (예 : 영화 감상) 또는 전문 지식이 관련되어있는 경우 활성화되도록 사용자가 자신의 전문 지식을 선택하도록 허용하는 일부 상자에 대한 것입니다. 이렇게하려면 autocomplete select 이벤트 내에서 $ .getJSON을 호출하려고합니다. $ .getJSON은 서버 측 php 스크립트를 호출합니다.이 스크립트는 방금 선택한 활동에 전문 지식이 필요한지 여부를 mysql 데이터베이스에 요청합니다. 그러나 .getJSON을 호출하지 않는 것 같습니다.jQuery 자동 완성 서버 측 스크립트 호출
다음<label for="activity">Select Activity:</label>
<input id="activity">
내 자바 스크립트입니다 :
$("#activity").autocomplete({
minLength: 2,
source: "php/getActivities.php",
select: function(event, ui) {
// Call the server side script to determine whether or not this activity
// requires expertise or not
queryString = 'activity=' + encodeURIComponent(ui.item.value);
alert (queryString);
$.getJSON('php/checkActivityExpertise.php',queryString,function(data2) {
alert('in .getJSON');
if (data2.needExpertise) {
activateBoxes();
}
else {
deactivateBoxes();
}
}); // end of $.getJSON call
} // end of select: function
}); // end of activity.autocomplete
그리고 여기에 PHP 함수입니다 : 여기
내 HTML입니다<?php // checkActivityExpertise.php
// Connect to database
include_once 'dbConnect.php';
include_once 'sanitizeString.php';
$activity = sanitizeString($_GET['activity']);
// query database on whether or not expertise is needed
$query = "SELECT displayExpertise FROM activities WHERE activity=$activity";
$resource = mysql_query($query);
$row = mysql_fetch_row($resource);
$needExpertise = $row[0];
// Return the flags back to calling function
$arr = array('needExpertise' => $needExpertise);
echo json_encode($arr);
?>
경고 (queryString이); 작품을 찾을 수 있습니다. 경고 ('.getJSON'); 그러나 작동하지 않습니다. 나는 모든 PHP 함수를 주석 처리하려고했습니다. 그래서 자동 완성 select 이벤트 내부에서 $ .getJSON을 호출 할 수 없는지 궁금합니다.
감사합니다,
톰
감사합니다. 내가 그거 했어. 그것은 나에게 오류를주고있다 : "요청 실패 : parsererror, SyntaxError : 예기치 않은 토큰 <"그 오류가 발생하는 이유를 모르십니까? – Tom78
당신의 querystring은 무엇입니까? – Starscream1984
querystring은 "activity = Aikido"입니다 (예 : 활동은 사용자가 텍스트 상자에 입력 한 내용에 따라 다름) – Tom78