I’m using the shorthand AJAX call, $.get but when I try and reference a variable with $(this), jQuery tells me that it’s undefined.
Here is the block of code:
$('.replaceWithObject').live('click', function(event) {
var cid = $(this).find('input').val();
$.get('GetVideoComment.ashx?cid=' + cid, function(data) {
$(this).html(data);
});
});
It finds the cid just fine, as $(this) is available prior to the $.get. Inside the .get $(this) is undefined. Setting a var to $(this) prior to the get doesn’t work either?
getVideoComment.ashx?cid=628 works, it returns a flash object. The issue is that $(this) is undefined inside the get.
Any idea on how to do what I want to do here? Or what I am doing wrong?
You need to cache your initial select so it exists when your callback fires.