-1

I need help with a little script.

In a bootstrap form the user should enter tags with autocomplete (database).

  <!-- Css Files-->


  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css"> 

  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tokenfield/0.12.0/css/bootstrap-tokenfield.min.css">


  <!-- JS Files -->

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tokenfield/0.12.0/bootstrap-tokenfield.js"></script>

   <div class="form-group">
    <label>Enter Tags</label>
    <input type="text" class="form-control" name="tokenfield" id="tokenfield" />
   </div>       


    <script type="text/javascript">
$('#tokenfield').tokenfield({
  autocomplete: {
    source: ['red','blue','green','yellow','violet','brown','purple','black','white'],
    delay: 100
  },
  showAutocompleteOnFocus: true
});
    </script>

It works ... but this ist without the database.

Now i tried this:

<script type="text/javascript">
$('#tokenfield').tokenfield({
  autocomplete: {

      source: function (request, response) {

          jQuery.get("tags_db.php", {

              query: request.term

          }, function (data) {

              // data = $.parseJSON(data);
              var t = [];
              $.each(data,function(k,v){
                t[k] = v.name;
              })

              response(t);

          });

      },



    delay: 100
  },
  showAutocompleteOnFocus: true
});
    </script>

Nothing happens ...

The Return of the tags_db.php is:

["red","blue","green","yellow","violet","brown","purple","black","white"]

The DB Connection works.

Where is my mistake???

Anyone have another solution???

Michael74
  • 33
  • 7

1 Answers1

0

I found the mistake.

After loading the JS files from above, I still loaded other JS files. That caused the problem. ;o((((((((

Michael74
  • 33
  • 7