【发布时间】:2019-10-18 11:49:04
【问题描述】:
我试图从 使用 ajax 的 API 获取一些信息。我能够发布数据,但我无法从服务器获取所有数据。我是 Django 环境中的新手,虽然我尝试了一些参考资料。 我想使用我提供的 API 从服务器获取数据,并使用 ajax get 调用显示这些数据。
我遵循的参考:
3.https://www.sourcecodester.com/tutorials/python/11762/python-django-simple-crud-ajax.html
我的 get 调用代码:
$.ajax({
type: "GET",
url: "/save_composition",
dataType: "json",
success: function(data) {
alert(data)
},
error: function(xhr, textStatus) {
alert("error..");
}});
网址部分:
path('restore_composition/', views.restore_composition, name='restore_composition')
Views.py:
def restore_composition(request):
data = SaveComposition.objects.all()
return render(request, 'index.html', context={'data': data})
【问题讨论】:
-
你在哪里定义了你的
save_compositionmethod/url? -
我在某些时候误解了。端点是问题。感谢您的合作。