TypeError: b.toLowerCase is not a function in bootstrap typeahead plugin

问题内容:

I am working on autocomplete search with typeahead plugin version 3.1.1. I used php, mysql, ajax and js/jquery.
When i used mysqli, it display perfectly when typing in search box but the problem is when i use PDO, it gives me an error called

“TypeError: b.toLowerCase is not a function”.

The problem is not PDO, i think the typeahead plugin.
If someone faced problem or someone has a solution, please help me to solve it.

The code is:
test.js:

$(document).ready(function () {

$('#search').typeahead({
    source: function (query, process) {
        return $.get('../../xdocs-admin/test/fetch.php', {query: 
 query}, function (data) {

            data= $.parseJSON(data);
            return process(data);
          });
      }

  });

});

php code, fetch.php:

$host = "mysql";
$username = "root";
$port = 3306;
$db = "xpans_plugs";
$password = "passroot";


  try {
     $connection = new PDO("mysql:host=$host;dbname=$db; port=$port", 
  $username, $password);
     $connection->setAttribute(PDO::ATTR_ERRMODE, 
     PDO::ERRMODE_EXCEPTION);

} catch (PDOException $e) {
  echo "The connection is failed: " . $e->getMessage();
}
    $sql = "SELECT * FROM search_test";
    $stmt = $connection->prepare($sql);
    $stmt->execute();


    $data = $stmt->fetchAll();


   while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
       echo $row['title'];
    }




     echo json_encode($data);

问题评论:

    
remove while() code from php file and then try
    
@AlivetoDie–Anantsingh, no change
– amiega
4 hours ago

答案:

答案1:

After:-

$stmt->execute();

Do:-

$data = array();

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  $data[] = $row['title'];
}
echo json_encode($data);

And check

答案评论:

    
Alive to Die, It works! Thanks bro … I think you will help me something further; that is, I fetch my data from the db and display in search box when i type a letter , however how can load it the one that i am targeted?
– amiega
2 hours ago
    
@amiega don’t forget to mark the answer as accepted
    
Alive to Die–Anant singh I already did… can you help me what i already asked you?
– amiega
2 hours ago

原文地址:

https://stackoverflow.com/questions/47752273/typeerror-b-tolowercase-is-not-a-function-in-bootstrap-typeahead-plugin

添加评论

友情链接:蝴蝶教程