This question has already been answered:

If the problem is related to the control of the received item using jquery. Before sending an ajax request, you can get all the attributes of an element and influence it as you like, but in the body of the success function, you cannot access it. Maybe you need to somehow pass this to the function body? I give the code:

/* Events after clicking on save button */ $("table").on('click', '.glyphicon-ok', function () { var rowId = $(this).attr('id'); //Здесь работает alert($(this).attr('id')); /* Change the icon of button */ $(this).removeClass('glyphicon-ok').addClass('glyphicon-pencil'); $.ajax({ url: path, type: 'POST', cache: false, data: data, success: function (response) { //Здесь не работает alert($(this).attr('id')); /* Change the icon of button */ $(this).removeClass('glyphicon-ok').addClass('glyphicon-pencil'); } }); }); 

You need to get the element completely, since in case of success of the request Ajax, its attributes will change.

Reported as a duplicate by the participants Grundy , Yura Ivanov , Pavel Mayorov , aleksandr barakin , user194374 Jun 30 '16 at 6:00 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    do like this var id= $(this).attr('id') before ajax

    and inside the success function use id

    • Thanks for the answer. But I need to get exactly this, since I need to change its attributes. - Valentine Murnik
    • 2
      so create a variable in the same way and assign it $ (this) before the Ajax, and inside it use the new object - Bogdan Gudyma
    • Thank you for what you need) - Valentine Murnik