Question

my problem is when i try to show a value by ajax calling,it shows the value to "generic" class but when i try to show it on the parent row it is not showing anything. here is my ajax code

$.ajax({
    type: 'POST',
    url: 'http://localhost/medical/index.php/purchase/test',
    data: 'data=' + pid,
    success: function() {
        $.get('http://localhost/medical/index.php/purchase/test', function(data) {
            $(this).parents('tr').find('.generic').html(data); // doesn't show the value
            $( ".generic" ).html(); // this show the value but in all table row
    });
}});

Thanks in Advance

Était-ce utile?

La solution

The problem is called scope. this in context of the anonymous function means something else than it means outside. You can do it like this

var that = this;
$.ajax({
    ...
    success: function() {
        $.get(..., function(data) {
            $(that).parents('tr').find('.generic').html(data);
        });
    }
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top