index.php

<html> <head> <title>ы</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript" src="jquery.autocomplete.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function(){ $("#search").keyup(function(){ $("#search").autocomplete("json.php", { delay:10, minChars:4, maxItemsToShow:3 } ); }); }); //?word=" + $("#search-text").val() </script> <form action=""><input type="search" id="search"> <input type="submit"></form> <body> 

json.php

 <?php echo json_decode($_GET['q']); 

How to make it work? Here you can use the json file?

  • one
    You mean how to implement the server part? - Vfvtnjd
  • Yes. maybe there are better solutions? - ferz
  • json_decode($_GET['q'], true) this once and twice --- NEVER do so;) process GET / POST requests without checking them will lead to disastrous consequences ... - thunder
  • Clearly need to do a check. The question was in the interaction of entities. - ferz
  • CORRECT ANSWER. echo 'word, word1, word2'; + lineSeparator: ',' - ferz

1 answer 1

Well, that's right (probably, it is better to refer to the autocomplete documentation) after getting the result back json_encode(ответ) in accordance with the autocomplete documentation :) Surely, the developer has examples on the site even?

A description of how it works is still there or is more suitable :)

json returned in the form you want, the last example shows this.

and generally speaking. have a great tutorial on your jqueryui autocomplete

  • there is no server side - ferz
  • then put firebug , for example, and see what autocomplete sends (in what format and with which variables) and what the server returns, in particular json.php if I correctly found your autocomplete, then everything is written:> The backend should output possible values for the autocompleter, each on a single line. Output cannot contain the pipe symbol "|", since it is considered a separator (more on that later). Using options you couldn’t have - thunder
  • api.jqueryui.com/autocomplete there is no such text, in any case, this is not an example. looked at the answer, 200ok. no body. echo json_decode ($ _ GET ['q']); there is an error, the question is where? - ferz
  • yes, I didn’t find it ... ^) but it’s not important, it works all the same, besides there’s a description of how it works :) - thunder