【发布时间】:2016-07-31 10:24:26
【问题描述】:
我有一个模态,我在其中呈现一个表单。在它打开它从 View 函数请求内容之前。现在我想传递我可以在 ajax.success: 函数中处理的其他属性。
阿贾克斯:
function task_form() {
$.ajax({
url : "/somewhere/" , // the endpoint
type : "GET", // http method
// handle a successful response
success : function(data) {
if(data.attr == "whatever"){
do this
}else{
do that
}},
// handle a non-successful response
error : function(xhr,errmsg,err) {
errorstuff
}
});
};
查看:
def someview(request):
if request.method == 'POST':
print("shouldnt happen")
else:
form = SomeForm()
response_data = {'form': form}
return render(request, 'formToInsert.html', response_data)
我尝试使用 JsonResponse() 但我不确定如何将 html 放入 dict 中以及如何在 js 端使用它。
【问题讨论】:
标签: jquery json ajax django django-views