我正在尝试在进行ajax调用后在“success”中找到jquery自动完成的选择器。在“成功”中,我正在寻找$(this)为$(“。itemDescInput”),但事实并非如此。那时我如何找到那个选择器呢?
$(".itemDescInput").autocomplete({
source: "invoices/invoice_items.php",
select: function(event, ui) {
var $it_desc = ui.item.value;
$.ajax({
type: "POST",
url: "invoices/invoice_items_prices.php",
data: "it_desc="+$it_desc,
success: function(result){
if(result != '') {
$(this).find("input .itemCostEach").val(result);
}
}
});
}
});
答案 0 :(得分:2)
在success()
内,this
不是指您的选择器,而是指 AJAX设置。您可以通过在this
来电中设置上下文来更改ajax()
指向的内容。请参阅documentation。
例如:
$.ajax({
context: this, // You could pass 'this' in directly if you wanted :)
success: function(result) {
// Refer to 'this' in the way you expect
}
});