Autocomplete with ajax works, but no with local data.

Autocomplete with ajax works, but no with local data.

Hi everyone!

I've decided to use local data instead of bring the data through ajax for the autocomplete because is to slow to do it that way.

Using ajax all works properly, slow but works, but If I try to use a .js file with all my strings it doesn't work, here the example working:

  1. <script>
  2. $("#inicio").on("pageshow", function(e) {
  3.    var sugList = $("#suggestions");

  4.    $("#searchField").on("input", function(e) {
  5.        var text = $(this).val();
  6.        if(text.length < 1) {
  7.            sugList.html("");
  8.            sugList.listview("refresh");
  9.        } else {
  10.             $.get("http://www.xxx.com/xxx/api/xxx?bu=1&li=1&lf=5", {ca:text}, function(res,code) {
  11. var str = "";
  12.                for(var i=0, len=res.length; i<len; i++) {
  13.                    str += "<li><a href='#'  data-role='button' data-iconpos='notext' onclick=\"seleccionar('"+res[i]+"');\">"+res[i]+"</a></li>";
  14.                }
  15.                sugList.html(str);
  16.                sugList.listview("refresh");
  17.                console.dir(res);
  18.            },"json");
  19.        }
  20.    });

  21. });
  22. function seleccionar(termino){
  23. $('#searchField').val(termino);
  24. $('#suggestions').html('');
  25. }
  26. </script>
if instead of use : 
      
  1.        $.get("http://www.xxx.com/xxx/api/xxx?bu=1&li=1&lf=5", {ca:text}, function(res,code) {
I use:
  1. $.get("js/autoComplete.js", {ca:text}, function(res,code) {
      It doesn't work, the content of autoComplete.js is the full list of string that the ajax give me, the structure is:


  1. "[\"Zaragoza (Provincia)\",\"Zamora (Provincia)\",\"Vizcaya (Provincia)\",\"Valladolid (Provincia)\",\"Valencia (Provincia)\"]"
The result is:


How is possible that in local data it doesn't work but with ajax it works being the same format....¿?

Thx!