我试图在执行我的Ajax调用后隐藏了input的父项,但由于某种原因它没有工作,没有发生效果,父项也未隐藏。ajax调用后执行jQuery函数时发生的问题
这里是我的JQuery的片断:
$(".getqty").mouseover(function() {
var split = this.id.split(":");
var color = split[0];
var size = split[1];
var prodID = split[2];
$.ajax({ //create an ajax request to loadstuff.php
type: 'POST',
url: 'includes/loadstuff.php',
dataType: 'html', //expect html to be returned
data:'color='+color+'&size='+size+'&prodID='+prodID,
success: function(response){
$(this).parent().hide(); //Problematic part
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
这是我的HTML:
我试图做的也许显得毫无意义,但它实际上是我试图理解为什么隐藏父项在悬停时不起作用。
但是我尝试了以下并在ajax调用之前隐藏了父项并且它工作正常。我不明白为什么。
$(".getqty").mouseover(function() {
var split = this.id.split(":");
var color = split[0];
var size = split[1];
var prodID = split[2];
$(this).parent().hide(); //Moved it here and it works. But I need it after the ajax call
$.ajax({ //create an ajax request to loadstuff.php
type: 'POST',
url: 'includes/loadstuff.php',
dataType: 'html', //expect html to be returned
data:'color='+color+'&size='+size+'&prodID='+prodID,
success: function(response){
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
2015-12-20
nTuply