Home > Backend Development > PHP Tutorial > javascript - 鼠标反复放在标签之上显示tag-pop但只ajax一次的问题

javascript - 鼠标反复放在标签之上显示tag-pop但只ajax一次的问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:43:21
Original
981 people have browsed it

点在segmentfault 内的标签上时会弹出框详细显示标签内容,但我在控制台发现反复滑动多次,ajax只有第一次发起了请求,请问这用到了什么技术

回复内容:

点在segmentfault 内的标签上时会弹出框详细显示标签内容,但我在控制台发现反复滑动多次,ajax只有第一次发起了请求,请问这用到了什么技术

第一次请求之后就把内容填写到DOM里面了,然后取消掉hover事件的AJAX监听部分(或者在DOM上用属性标记它已经填充了内容之类的)这样就可以吧。

我的猜测啊,

<code>var api = {};
$ajaxForm.on('submit',
function(event) {
    event.preventDefault();
    $response.empty();
    var search = $('#title').val();
    if (search == '') {
        return;
    }
    $response.addClass('loading');
    if (!api[search]) {
        api[search] = $.ajax({
            url: 'http://book.learningjquery.com/api/',
            dataType: 'jsonp',
            data: {
                title: search
            },
            timeout: 15000
        });
    }
    api[search].done(response).fail(function() {
        $response.html(failed);
    }).always(function() {
        $response.removeClass('loading');
    });
});
</code>
Copy after login

(代码来自于jQuery基础教程 13.3.2 缓存响应)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template