This is related to the question I asked at http://stackoverflow.com/questions/2802948/how-to-make-an-ajax-call-immediately-on-document-loading
I am trying to get a String delimited by | characters from the server to use as input for jQuery's .autocomplete() plugin. If I have a local variable declared in the code then it works fine, but if I try to define this variable using an ajax call to the server it doesn't work even though the alert shows that I have populated the variable "dataArray" with exactly the same characters.
My code (that doesn't work) is:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "../AutoComplete",
success: function(data) {
var dataArray = data;
alert(dataArray);
$("#example").autocomplete(dataArray);
}
});
});
The value that is printed in the alert is:
"Manuscript|Text|Information Object|Basketball|Ball|Sporting Equipment|Tarantula|Spider|Australian Spider|Cricket Player|Medieval Artefact|Person|Sportsperson|Leonardo Da Vinci|Country|Language|Inventor|Priest|Electronics Manufacturer|Object|letter|Artefact|governance model|Organism|Animal".split("|");
If instead I do this (although this not a solution):
$(document).ready(function(){
$.ajax({
type: "GET",
url: "../AutoComplete",
success: function(data) {
var dataArray = "Manuscript|Text|Information Object|Basketball|Ball|Sporting Equipment|Tarantula|Spider|Australian Spider|Cricket Player|Medieval Artefact|Person|Sportsperson|Leonardo Da Vinci|Country|Language|Inventor|Priest|Electronics Manufacturer|Object|letter|Artefact|governance model|Organism|Animal".split("|");
alert(dataArray);
$("#example").autocomplete(dataArray);
}
});
});
The autocomplete works fine?