I do jQuery.post in a php file and the file returns me a value.
jQuery.post
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
$(this)
null
$(".class").live("focusout", function(){ jQuery.post("phpfile.php", { someValue: someValue }, function(data) { // why the $(this) dosent work in the callback ? } ) });
In this case, this no longer the same object. Save the link until and use later:
this
$(".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; } ) });
$(".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.