how to pass $(this).data() in ajax request - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, October 5, 2022

how to pass $(this).data() in ajax request

i need to pass $(this).data into success func in ajax. here is my code

var product_id = $(this).data("product_id");

var url = "";

$.ajax({
  url: url,
  type: "POST",
  dataType: "json",
  data: {
    product_id: product_id,
    _token: "",
  },
  success: function (data) {
    $(this).addClass("wishlist-comp-saved");
  },
});

But $(this).addClass('wishlist-comp-saved'); is not working inside success: function(data) {}



source https://stackoverflow.com/questions/73937470/how-to-pass-this-data-in-ajax-request

No comments:

Post a Comment