I want to get data through Ajax and fill them into div .content, but it won’t work.
HTML:
<div class="review">
<span class="seefull" rel="1">see full content</span>
<div class="content"></div>
<div class="c_createtime">(06-15 04:03:13)</div>
</div>
<div class="seg_r"><img src="http://img.dachaocai.com/sys/seg_2.gif"/></div>
<div class="review">
<span class="seefull" rel="2">see full content</span>
<div class="content">12</div>
<div class="c_createtime">(07-31 12:46:18)</div>
</div>
jQuery:
$(function() {
$(".seefull").click(function() {
$.ajax({
url: "/j/fullreview",
data: {"t":"b","id":$(this).attr("rel")},
success: function(data) {
$(this).find("div .content").html(data);
}
})
})
})
It’s about the context of “this”.
When the ajax callback function executes, this does not refer to your original object anymore. So, you need to store its original reference on a variable, and use to that variable from there on to be sure you are always referring to the right element.
With the above code, your object is now stored in the $this variable.
Find the parent of our element, then find the element with class “content”, and change its content.
I didn’t find a div of class content because from your code there is only one element with that class.