From jQuery UI site (veiw source):
$( "#birds" ).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 );
}
});
So as I see there is no options how to make ajax request with post data to the "search.php"
.
But I need to do that to send some filter from previous input field (current field: city, previous field: country).
How to do that?
Thanks!
Add web form right click on project add new item and choose web form. Add script and styles cdn link in head section. Design HTML by grad and drop textbox control in web form. Complete html code of web form.
In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.
Advertisements. Auto completion is a mechanism frequently used in modern websites to provide the user with a list of suggestions for the beginning of the word, which he/she has typed in a text box. The user can then select an item from the list, which will be displayed in the input field.
ui-autocomplete : The menu used to display matches to the user. ui-autocomplete-input : The input element that the autocomplete widget was instantiated with.
Try changing the source to be a method which uses $.post:
$("#birds").autocomplete({
source: function (request, response) {
$.post("search.php", request, response);
},
...
$( "#birds" ).autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
url:"search.php",
data: request,
success: response,
dataType: 'json'
});
}
}, {minLength: 3 });
//-------------------------
//search.php - example with request from DB
//
$link = mysql_connect($mysql_server, $mysql_login, $mysql_password)
or die("Could not connect: " . mysql_error());
mysql_select_db($mysql_database) or die("Could not select database");
mysql_set_charset('utf8');
$req = "SELECT mydata FROM $mysql_table WHERE mydata LIKE '".$_REQUEST['term']."%' ORDER BY mydata ASC";
$query = mysql_query($req);
while($row = mysql_fetch_array($query))
{
$results[] = array('label' => $row['mydata']);
}
echo json_encode($results);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With