I'm banging my head here trying to figure out why this isn't working, so I finally created a simplified version of what I'm going on jsFiddle, and of course it works there.
What I'm doing - a simple AJAX call on hover over an element, and putting that response in a DIV. Here's the code on my site that is NOT working...
HTML
<div class="profileimage">
<a href="#">
<img src="/profilepics/img.jpg" />
<p>Test Here</p>
</a>
<div class="profileInfo"></div>
</div>
jQuery
$(document).ready(function() {
$('.profileimage').hover(function() {
$.ajax({
url:"getProfile.php",
success:function(HTML){
$(this).find('.profileInfo').html(HTML);
}
});
});
});
Also, for reference, all that's in getProfile.php currently is:
<p>RESULTS FROM AJAX</p>
What DOES work is that the AJAX request happens, the result is returned okay. If I replace the line in the success function with alert(HTML)
, I can see the response. What does NOT work is that the response never makes it in to the profileInfo
child element.
I assumed my locator was incorrect, so I created a jsFiddle (HERE) to test. Turns out, the locator works just fine.
So I guess my question here is... if the locator works okay in the jsFiddle, but not in the AJAX request... is there something about the way it's used in an AJAX call that I need to change? I don't see why $(this).find('.profileInfo').html(HTML);
shouldn't work just fine regardless of whether I'm using it in an AJAX response or not.
Any thoughts / suggestions are appreciated...