How do I get this jQuery autocomplete code to work in FireFox?

て烟熏妆下的殇ゞ 提交于 2019-12-24 09:26:58

问题


Hey guys, I've got this jQuery code which works in Chrome and Safari but not on IE or FireFox. What could be wrong 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?


回答1:


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");
        }
});


});


来源:https://stackoverflow.com/questions/6169954/how-do-i-get-this-jquery-autocomplete-code-to-work-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!