JQuery unknown "this" inside ajax request -
I need an AJAX request when changing the class attribute, but I do not have access to "this" inside Ajax Request Can
$ ('shopping'). Click to get the id (function () {// id attribute var id = $ (this) .attr ('id'); // Send the id attribute in Ajax $ $ Request ('ProcessAd.ToShopping.fp? Id =' + ID, Function (Data) {if (Data == "Success") {// Success of change $ (this) .attr ('class', 'new'); // "this" no longer access can}});});
Set a reference variable:
$ ('.shopping'). Click (function () {// id attribute var id = $ (this) .attr ('id'); var which = this; // Enter the Ajax Request $ id id attribute. ('ProcessAddToShopping.php? Id = '+ Id, function (data) {if (data == "success") {// success of success ($) is that .attr (' class', 'new')}}};});
Comments
Post a Comment