Javascript AJAX-页面刷新时的双重结果

Javascript AJAX-页面刷新时的双重结果,javascript,jquery,xml,ajax,Javascript,Jquery,Xml,Ajax,我有一段代码,其中使用AJAX显示XML提要中的一些位置: $.ajax({ type: "GET", url: "testxml.xml", dataType: "xml", success: function(xml) { $(xml).find("Country[Name='"+localStorage.ArrivalCountry+"']").find('Destination').each(function(){

我有一段代码,其中使用AJAX显示XML提要中的一些位置:

$.ajax({
    type: "GET",
    url: "testxml.xml",
    dataType: "xml",
    success: function(xml) {
        $(xml).find("Country[Name='"+localStorage.ArrivalCountry+"']").find('Destination').each(function(){
            var destinationName = $(this).attr('Name');
            $('<a class="listItem" href="#" id="'+destinationName+'">'+destinationName+x+'<div class="arrow"></div></a>').appendTo('#destinationList');
        });

    }
});
$.ajax({
键入:“获取”,
url:“testxml.xml”,
数据类型:“xml”,
成功:函数(xml){
$(xml).find(“国家[名称='”+localStorage.ArrivalCountry+“']”)。find('Destination')。每个(函数(){
var destinationName=$(this.attr('Name');
$(“”).appendTo(“#destinationList”);
});
}
});
第一次它正确显示,但如果我刷新页面,它会将每个结果显示两次。如果我再做一次,它会显示三次,以此类推

在添加更新集之前,您需要
empty()
来自
#destinationList
的先前AJAX调用数据:

$.ajax({
键入:“获取”,
url:“testxml.xml”,
数据类型:“xml”,
成功:函数(xml){
$(“#destinationList”).empty();//这将清除前面附加的所有“a”元素
$(xml).find(“国家[名称='”+localStorage.ArrivalCountry+“']”)。find('Destination')。每个(函数(){
var destinationName=$(this.attr('Name');
$(“”).appendTo(“#destinationList”);
});
}
});
有关

的详细信息在添加更新集之前,您需要从
#destinationList
中删除先前AJAX调用的数据:

$.ajax({
键入:“获取”,
url:“testxml.xml”,
数据类型:“xml”,
成功:函数(xml){
$(“#destinationList”).empty();//这将清除前面附加的所有“a”元素
$(xml).find(“国家[名称='”+localStorage.ArrivalCountry+“']”)。find('Destination')。每个(函数(){
var destinationName=$(this.attr('Name');
$(“”).appendTo(“#destinationList”);
});
}
});

有关

Ajax调用返回什么的更多信息???给我们一个例子…你的Ajax调用返回什么???给我们举个例子,他写道他刷新了页面,所以由于web应用程序是无状态的,所以不需要它。如果我没听错的话,谢谢。解决了这个问题:DHe写道他刷新了页面,所以由于web应用程序是无状态的,所以不需要它。如果我没听错的话,谢谢。解决了这个问题:D