我的观点清楚地返回了我想要的数据,但事实是我无法将这些数据加载到特定的div中,我在下面显示了div标记。
我的观点如下
def pop_user(request, username):
print('user')
data = dict()
profile = get_object_or_404(User, username=username)
context = {'profile': profile}
data['html_form'] = render_to_string('profile/pop_user.html',
context,
request=request,
)
return JsonResponse(data)
我的js / ajax是这样的:
$(document).ready(function() {
$('.user').hover(function (e) {
// alert($(this).closest(".username").attr("data-url"))
var offset = $(this).offset();
var left = e.pageX;
var top = e.pageY;
var theHeight = $('#myPopoverContent').height();
$('#myPopoverContent').show();
$('#myPopoverContent').css('left', (left+10) + 'px');
$('#myPopoverContent').css('top', (top-(theHeight/2)-10) + 'px');
$.ajax({
url: $(this).closest(".username").attr("data-url") +"/",
type: 'get',
data: form.serialize(),
dataType: 'json',
success: function (data) {
$("#myPopoverContent").html(data.html_form);
}
});
});
$('#myPopoverContent').focusin(function (e) {
$('#myPopoverContent').active();
});
$('#myPopoverContent').mouseout(function (e) {
$('#myPopoverContent').hide();
});
$('.user').mouseout(function (e) {
$('#myPopoverContent').hide();
});
});
我的HTML是
<div id="myPopoverContent" class="dealBg">
</div>