Autocomplete does not work when the first character is 0

Does anyone know why my autocomplete doesn't work when the first character I enter 0 (zero)? For debugging purposes, I configure my AC to just tell me that the string is found or not, and it seems that for any character that I type as the first character, it tells me so, except 0. I have to enter the second character after 0 for it to get started and get started. It is as if the minLength 2 attribute, when the first char is 0. Has anyone come across this or heard about it and knew how to fix it? Here is my code:

 //AutoComplete code in question $(function() { var itemcode_ac = { source: "/webservices/whs_bincodeAC.php", select: function(event, ui) { $('#txtBin').val(ui.item.value); getWhsInfo(); }, minLength: 1 } $('#txtBin').autocomplete(itemcode_ac); }); 

whs_bincodeAC.php:

 <?php if(isset($_GET["term"]) && !empty($_GET["term"])) { include_once $_SERVER['DOCUMENT_ROOT'].'/path/to/dbConnect.php'; $term = mysql_real_escape_string(trim($_GET["term"])); //wildcard appended here for parameterized query (MySqli) $term .= "%"; $query = "SELECT DISTINCT BinCode, ItemCode, ItemName, WhsCode, DataAsOfDate FROM whse_tbl WHERE BinCode LIKE '$term' or ItemCode LIKE '$term' ORDER BY BinCode LIMIT 0, 10"; $res = mysql_query($query); //This is the debug code I described above /*if($row = mysql_fetch_assoc($res)) echo json_encode(array(array('value' => "is row"))); else echo json_encode(array(array('value' => "no row"))); return;*/ $matches = array(); while($row = mysql_fetch_assoc($res)) { $matches[] = array('value' => $row["BinCode"], 'label' => $row["BinCode"].' - '.$row["ItemCode"], 'name' => $row["ItemName"], 'whscode' => $row["WhsCode"], 'asOfDate' => $row["DataAsOfDate"]); } echo json_encode($matches); } ?> 

Note. My boss forces me to use MySql, not the MySqli extension.

+4
source share
1 answer

Perhaps you are doing something like the following.

if(empty($_GET["bin"])) or if(!$_GET["bin"]) to check its value.

But in this case, if bin is 0 , the first case leads to true , and the second to false .

So use isset($_GET["bin"]) .

+4
source

Source: https://habr.com/ru/post/1437430/


All Articles