【发布时间】:2012-07-04 07:26:04
【问题描述】:
我想知道进行 ajax 调用以更新用户名列表的最佳选择是什么。我也可以
一个。执行 ajax 调用并取回用户对象并构建 html 并将其附加到 div 中
build_html = function(obj) {
html = 'username - ' + obj.username
$('#container').append(html);
}
b.执行 ajax 调用并让 django 返回 html。
response = render_to_response ('user_item_template.html', {'user' : user})
return response._container
如果响应成功,我会将其附加到容器 div 中。
使用方法“b”是否有任何缺点,因为根据具体情况,在 javascript 中构建 html 可能会出现未转义字符等问题,而且一般来说很混乱。
谢谢
【问题讨论】:
标签: django templates django-templates templating