How do I get this jQuery autocomplete code to work in FireFox?
Hey guys, I've got this jQuery code which works in Chrome and Safari but not on IE or FireFox. What could be wron开发者_JAVA技巧g with it?
<script>
$(document).ready(function() {
var myArr = [];
$.ajax({
type: "GET",
url: "airports.xml",
dataType: "xml",
success: parseXml,
complete: setupAC,
failure: function(data) {
alert("XML File could not be found");
}
});
function parseXml(xml)
{
//find every query value
$(xml).find("airport").each(function()
{
myArr.push($(this).attr("label"));
});
}
function setupAC() {
$("input#depart_from").autocomplete({
source: myArr,
minLength: 1,
select: function(event, ui) {
$("input#depart_from").val(ui.item.value);
$("#submitform").submit();
}
});
}
});
</script>
And here is my input element
<input id="depart_from" type="text" name="depart_from" placeholder="Depart from"/>
Any suggestions?
OK, revised answer. Changed dataType to html and fix errors in xml document:
$(document).ready(function() {
var myArr = [];
function parseXml(xml)
{
//find every query value
$(xml).find("airport").each(function()
{
myArr.push($(this).attr("label"));
});
}
function setupAC() {
$("input#depart_from").autocomplete({
source: myArr,
minLength: 1,
select: function(event, ui) {
$("input#depart_from").val(ui.item.value);
$("#submitform").submit();
}
});
}
$.ajax({
type: "GET",
url: "airports.xml",
dataType: "html",
success: parseXml,
complete: setupAC,
failure: function(data) {
alert("XML File could not be found");
}
});
});
精彩评论