$documentonclick qq_add_to_cart_list function var item_id = $thisattrdata_child; $ajax$this not working in ajax success why
The reason $this is not working in the Ajax success function is because the context of $this changes within the success function. When the Ajax request is made, the success function is executed in a different scope, and the this keyword refers to the Ajax object instead of the clicked element.
To access the clicked element within the success function, you can store the reference to $this in a variable outside of the Ajax call, and then use that variable within the success function. Here's an example:
$(document).on('click', '.qq_add_to_cart_list', function() { var $this = $(this); var item_id = $this.attr("data_child");
$.ajax({ // Ajax options here
success: function(response) {
// Use $this here
}
}); })
AI 优化版
原文地址:https://www.cveoy.top/t/topic/iuuq 著作权归作者所有。请勿转载和采集!