Я использую Bootstrap 3.3.6, JQuery 1.11.0, Bootstrap3-typeahead 4.0.2 и bootstrap-tagsinput 0.8.0.Невозможно получить taginput-typeahead для работы с удаленным источником MySQL
Вот мой код:
$(function() {
$('.tagsinput-typeahead').tagsinput({
confirmKeys: [13],
itemValue: 'value',
itemText: 'text',
typeahead: {
displayKey: 'text',
afterSelect: function(val) { this.$element.val(""); },
source: function (query) {
return jQuery.get("typeaheadSource.php?q=" + query);
// return jQuery.post("typeaheadSource.php?q=" + query); // I tried both get and post
}
}
});
});
<div class="form-group">
<label class="control-label col-md-3">Job Number(s) </label>
<div class="col-md-8">
<select multiple="multiple" class="form-control tagsinput-typeahead" name="typeahead" id="typeahead" ></select>
</div>
</div>
А вот мой typeaheadSource.php:
if (isset($_REQUEST['q'])) {
$query = $_REQUEST['q'];
$sql = "SELECT jobno, jobname FROM jobs WHERE jobno LIKE '%" . $query . "%' ORDER BY jobno DESC LIMIT 20";
$result=db_query($sql);
while($row = db_nextrow($result)) {
$array[] = array('value' => $row['jobno'], 'text' => $row['jobname']);
}
if (isset($array)) {
echo json_encode($array);
}
}
выход, если я бегу typeaheadSource.php непосредственно выглядит следующим образом:
[{"value":"2012006.00","text":"Monterey Hotel Investigation"},{"value":"2006142.00","text":"Ollendorff Residence"},{"value":"2006141.01","text":"MLK Student Union Peer Review Expanded Scope"},{"value":"2006141.00","text":"MLK Student Union Peer Review"}]
И если я возьму этот вывод &, поставьте его в мой код как источник, все отлично работает.
$('.tagsinput-typeahead').tagsinput({
confirmKeys: [13],
itemValue: 'value',
itemText: 'text',
typeahead: {
displayKey: 'text',
afterSelect: function(val) { this.$element.val(""); },
source: [{"value":"2012006.00","text":"Monterey Hotel Investigation"},{"value":"2006142.00","text":"Ollendorff Residence"},{"value":"2006141.01","text":"MLK Student Union Peer Review Expanded Scope"}]
}
});
Но когда мой источник называет мой удаленный URL, то машинописный не появляется & я не получаю никаких ошибок.
source: function (query) {
return jQuery.get("typeaheadSource.php?q=" + query);
}
Кто-нибудь есть какие-либо предложения или советы о том, как заставить это работать с удаленным URL запроса к БД MySQL?