Use $ (this) in ajax callback jquery

I do jQuery.post in a php file and the file returns me a value.

the question is: why does the $(this) dosent function work in a callback function? any signal transmitting something to show using $(this) return me null

 $(".class").live("focusout", function(){ jQuery.post("phpfile.php", { someValue: someValue }, function(data) { // why the $(this) dosent work in the callback ? } ) }); 
+4
source share
2 answers

In this case, this no longer the same object. Save the link until and use later:

 $(".class").live("focusout", function(){ var $this = $(this); jQuery.post("phpfile.php", { someValue: someValue }, function(data) { // 'this' inside this scope refers to xhr object (wrapped in jQuery object) var x = $this; } ) }); 
+13
source
 $(".class").live("focusout", function(){ var this = $(this); jQuery.post("phpfile.php",{ someValue: someValue },function(data){ // Now use this instead of $(this), like this.hide() or whatever. }) }); 

$ (this) in your example referred to $ .post, I think.

+2
source

All Articles