Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im using autocomplete of jqueryui (http://jqueryui.com/autocomplete/#remote) and the source comes from "source: "search.php""

This code ...

JavaScript
 $( "#name" ).autocomplete({
source: "search.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
}); 


.. And this code below together works perfectly fine! but autocomplete suggest me "All of my Data" ! not smth like my term.

PHP
<?php
require('inc/tunel.php');
$keyword = $_POST['keyword'];
$respons = array();
$fetch_engine = $db->query("SELECT name FROM `engine`");
    while($read_engine = $fetch_engine->fetch(PDO::FETCH_ASSOC)) {
        $respons[] = $read_engine['name'];
        }

        echo json_encode($respons);
 ?>


i also tried this code below, my problem solved, but i dont want to see my data in "view source" of my document!

JavaScript
$( "#name" ).autocomplete({
source: <?php
	require('inc/tunel.php');

	$respons = array();
	$fetch_engine = $db->query("SELECT name FROM `engine`");
		while($read_engine = $fetch_engine->fetch(PDO::FETCH_ASSOC)) {
			$respons[] = $read_engine['name'];
			}
			
			echo json_encode($respons);
			

?>,
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
}); 
Posted
Updated 7-Dec-14 6:37am
v2
Comments
Afzaal Ahmad Zeeshan 7-Dec-14 11:51am    
In which part do you want help?

I think that source: 'file.php' part needs help. You want to know how to create an ajax request.
amin khoshzahmat 7-Dec-14 11:59am    
hey Afzaal Ahmad Zeeshan :)

i want to auto complete when im typing, and do it with ajax.
and i dont know how to do this in search.php file, i mean how to post it and return results (LIKE %$term%).

you know, my data in DB is valueable, and i dont wanto to reveal all of my data, i just want to show smtl close to the term, not all of them.

JQuery UI Autocomplete widget communicates with the server via GET and not POST.
The actual URI when asking for values will be .../search.php?term=[what you have entered]...
So in PHP you can get the value using $_GET['term']...
 
Share this answer
 
XML
hi,

try this

it may help

https://www.devbridge.com/sourcery/components/jquery-autocomplete/
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900