I'm trying to use jquery autocomplete for a text input. What I want is that when user types a letter, results starting with the specified letter will be shown from an xml source. But I can't make it work. As I'm quite new in jquery, I don't know what I'm doing wrong. Please help :)
Also I tested the php file, it works fine as xml
Here's the code
$("#names").autocomplete({
source: function(request , response){
$.ajax({
type: 'GET',
url: 'name.php',
dataType: "xml",
data: "letter="+request,
success: function(data) {
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
var array = [];
var i = 0;
$(xml).find('nameslist').each(function(){
array[i] = $(this).find("name").text();
i++;
});
}
});
response(array);
},
minLength: 1
});