我研究了几十个答案,但找不到解决方案。
我在鼠标悬停时调用了 jQuery Ajax。我在浏览器控制台中看到一个日志。但是 PHP 端收到 2 个请求。
我的 JS 代码:
$('.df_word').off("mouseover").on("mouseover", function(){
console.log("open translation_box"); //fires once on hover
get_translation($(this),$(this).html());
}
function get_translation(word_el,word_html){
console.log('get_translation'); //fires once on hover
var params = {}
params['api'] = "2.0";
params['page'] = "translate";
params['q'] = ""+word_html+"";
console.log(params); //fires once on hover
$.ajax({
type: "GET",
crossDomain: true,
contentType: 'application/json; charset=utf-8',
url: window.api_link,
data: params,
error: function( xhr, textStatus ) {
console.log(xhr.status);
},
success: function(data){
console.log(data); //fires once on hover
}
});
}
在 PHP 方面,我在同一秒内看到 2 个请求(我将每个请求都保存到数据库中)。
我错过了什么?