【发布时间】:2013-03-19 22:55:36
【问题描述】:
我正在尝试创建一个 ajax 函数,该函数在调用时会将信息返回到新创建的模式,您能帮我找出问题所在吗?每当我尝试访问问题,下面我添加了我的终端和所有相关文件的屏幕截图。
views.py
@require_POST()
def form_create(request, model):
if request.method == "POST":
return HttpResponse("the model requested is")
urls.py
url(r'^forms/(?P<model>[\W-]+)/$','.views.form_create'),
html 模板中的 Ajax 调用
$.ajax({
url: "/forms/"+model+"/",
type: "POST",
cache: false,
success:
function(result){
$("#myModalLabel").html(result);
$("#companyModal").modal("show");
},
error:
function(xhr){
alert("Error: " + xhr.statusText);
return false;
}
});
【问题讨论】:
-
您是否设置了 DEBUG=True?
-
当然我设置为 True
-
因为你访问post,所以在ajax中定义csrf
标签: ajax django jquery django-views