That error occurs because this usually refers to the ajax object and not on the DOM element, to prevent this assign this in a variable like below:
/* To add add-on-test in cart */
$(document).on("click", ".aish_test", function(){
var thisButton = this; //Like this assign variable to this
var array_coming = '<?php echo json_encode($order_summary_array);?>'; //Json Encoding array intersect variable
//Converting in array
var array_check = $.parseJSON(array_coming);
var result = [];
for(var i in array_check){
result.push(array_check [i]);
}
//Fetching data:
var test_data_name = $(this).attr("data-name");
var test_data_price = $(this).attr("data-price");
var test_data_id = $(this).attr("data-id");
if($.inArray(test_data_id, result) == -1)
{
//static html
var static_html = '<tr><td>'+test_data_name+'</td>';
static_html += '<td>£'+test_data_price+'</td>';
static_html += '<td><button type="button" class="close remove_add_test" data-id="'+test_data_id+'" data-price="'+test_data_price+'" aria-hidden="true"> <i class="fa fa-trash-o"></i> </button></td></tr>';
/*ajax call*/
$.ajax(
{
type: 'POST',
url: 'scripts/ajax/index.php',
data: {
method: 'addtocart',
id: test_data_id,
name: test_data_name,
price: test_data_price
},
dataType: 'json',
success: function(data) {
if (data.RESULT == 0) {
$(thisButton).text("added to cart"); //Use again like this
$(".cart-number").text(data.productcount);
$.growl.notice({
title: "Shopping Cart",
message: data.MSG
});
$('#myTable tr:first-child').after(static_html);
} else if (data.RESULT == 2) {
$.growl.error({
title: "Shopping Cart",
message: data.MSG
});
} else {
$.growl.error({
title: "Shopping Cart",
message: data.MSG
});
}
}
});
}
else
{
$.growl.error({
title: "Shopping Cart",
message: "Already in Cart"
});
}
});