0
I have the following file:
index php.
<script type="text/javascript">
function montaAutocomplete(source) {
$( function() {
var availableTags = [ source ];
$( "#autocomplete" ).autocomplete({
source: availableTags
});
} );
}
</script><script>
function busca_palavra(x){
$.ajax({
type:"GET",
url: "autocomplete_sugestoes_descricao.php?q=" + x,
dataType:'text',
success : function(data) {
montaAutocomplete( data );
}
});
}
</script>
And the file that generates the result:
autocomplete_sugestoes_descricao.php
<?php
require "../conexao_ajax.php";
$q = preg_replace("/[^0-9A-Za-z]-/", "",$_GET['q']);
$q_formatado = '%'.$q.'%';
if(!empty($q)){
$busca_descricao = $link->prepare("SELECT id, descricao FROM ctrl_bancario WHERE descricao LIKE ? ORDER BY descricao ASC LIMIT 10");
$busca_descricao->bind_param("s", $q_formatado);
$busca_descricao->bind_result($id, $descricao);
$busca_descricao->execute();
$busca_descricao->store_result();
if($busca_descricao->num_rows() > 0){
echo "[";
while ($busca_descricao->fetch()) {
echo "$descricao, ";
}// Esta chave fecha o while ($busca_descricao->fetch()) {
echo "]";
} // Esta chave fecha o if($busca_descricao->num_rows() > 0){
} // Esta chave fecha if(!empty($q)){
?>
I am being able to receive the data normally, however, if I have two records in my table:
my application is returning the data this way on autocomplete of index php.:
as if there was no break in line or correct interpretation of the data.
How could I proceed at the time of processing this data from the archive autocomplete_sugestoes_descricao.php
in the variable var availableTags = [ source ];
?
I hope to get this result:
Your problem seems to be in "availableTags", have to post it next to the question?
– teliz
The result of my query returns just like this: [Test Deposit , test, ]
– WebCraft
And "availableTags" is being declared in the first script of the index.php file
– WebCraft
I am basing myself on this example to build my: https://jqueryui.com/resources/demos/autocomplete/default.html
– WebCraft