使用jquery ajax进行mousemove时,从数据库中获取重复数据

时间:2015-12-29 02:38:06

标签: php jquery ajax

我有从数据库获得的数据,以及它在display.php中的数据。

然后mousemove用于显示数据。但是当鼠标悬停时数据不断重复。这是鼠标移动的代码

$(line.node).mousemove(get_over_handler(country));

这是函数get_over_handler(country)

中的一些代码
function get_over_handler(country) {
    return function (event) {
        color_country(country, selected_color);
        var country_name = $("#country_name_popup");
        country_name.empty();
        country_name.append("<span id='popup_country_name'> " + code_to_name[country] + "</span><table width='100%' style='border-spacing:20px;'>");
        var id_dataset = $("#dataset_select").find('option:selected').attr('id');
        $.ajax({
            type: "POST",
            url: "display.php",
            data: {ibukota: country, id_dataset: id_dataset},
            success: function (data) {
                country_name.append(data);
            }
        });

我的问题是如何防止我从数据库中获得重复的数据?

1 个答案:

答案 0 :(得分:2)

将您的功能重写为:

function get_over_handler(country) {
    return function (event) {
        color_country(country, selected_color);
        var id_dataset = $("#dataset_select").find('option:selected').attr('id');
        $.ajax({
            type: "POST",
            url: "display.php",
            data: {ibukota: country, id_dataset: id_dataset},
            success: function (data) {
                var country_name = $("#country_name_popup");
                country_name.empty();
                country_name.append("<span id='popup_country_name'> " + code_to_name[country] + "</span><table width='100%' style='border-spacing:20px;'>");
                country_name.append(data);
            }
        });
    }
}