我研究了很多答案,但找不到解决方法。
我将鼠标悬停在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个请求(我将每个请求保存到数据库中。)
我想念什么?