我找到了解决原始问题的方法。将其发布在此处作为答案,希望对你有所帮助。
jQuery:
var postUrl = "http://localhost:8000/ingredients/";$('li').click(function(){ values = [1, 2]; var jsonText = JSON.stringify(values); $.ajax({ url: postUrl, type: 'POST', data: jsonText, traditional: true, dataType: 'html', success: function(result){ $('#ingredients').append(result); } }); });/成分/视图:
def ingredients(request): if request.is_ajax(): ourid = json.loads(request.raw_post_data) ingredients = Ingredience.objects.filter(food__id__in=ourid) t = get_template('ingredients.html') html = t.render(Context({'ingredients': ingredients,})) return HttpResponse(html) else: html = '<p>This is not ajax</p>' return HttpResponse(html)


