I have this code
$.post("recommend.php",{"jid":jid,"vid":vid,"eid":eid},function(data){
if(data=="1")
{
$(this).text("Recommended");
}
else
{
$(thelink).text("Recommend");
}
});
the post is executed properly but the text on the link is NOT changing though data is equal to 1. Any help…
thisrefers to the current context. In your AJAX callback it is different from the one of your calling function.However, you can simply preserve it by using
var $this = $(this);and then use$thisinside the callback instead of$(this);Of course another name would work, too. For example to preserve a plain
thislots of people useselforthat.Another solution would be using
$.ajax({ context: this, ...... }));to keep the same context inside the callback (if unspecified,thispoints to the options object passed to$.ajax())