jQuery .load() 在 Django 中不起作用
我正在尝试调用 Django 中的 url 并加载其内容。现在我有:
<script>
$('.myClass').load('{% url update_dropdown %}',
{'kind': "Book" },
function(data){
alert(data);
});
</script>
然后 update_dropdown 引用的视图是:
@csrf_exempt
def update_dropdown(request):
category = request.POST.get('kind', None)
all =False;
args = {
"label":category,
"all":all
}
return render_to_response('template.html',(args))
但是, .load() 由于某种原因将无法工作。如果我直接访问 URL,它会显示我期望的数据,但 .load() 不会配合。我知道这不是显示问题,因为警报将不起作用(除非我删除 @csrf_exempt,然后它会警告错误页面的 HTML)
我对发生的情况感到非常困惑,并且我一直在调试此问题并试图找到错误几个小时,任何帮助将不胜感激。
如果我将返回类型设置为 JSON 对象并使用 getJSON(),我可以让它工作,但我不想这样做
I'm trying to make a call to a url in Django and load the contents of it. Right now I have:
<script>
$('.myClass').load('{% url update_dropdown %}',
{'kind': "Book" },
function(data){
alert(data);
});
</script>
And then the view that update_dropdown refers to is:
@csrf_exempt
def update_dropdown(request):
category = request.POST.get('kind', None)
all =False;
args = {
"label":category,
"all":all
}
return render_to_response('template.html',(args))
However, the .load() won't work for some reason. If I go directly to the URL it shows the data I expect, but .load() won't cooperate. I know it's not a display issue, as the alert will not work (unless I remove the @csrf_exempt, then it alerts the HTML of the error page)
I'm pretty confused as to what's going on, and I've been debugging this and trying to find the error for hours now, any help would be appreciated .
I can get it to work if I make the return type a JSON object and use getJSON(), but I'd prefer not to
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将其包装在 ready 中:
Try wrapping it in a ready:
显然这是我使用的 jQuery uiSelect 库的问题。它已经过时并导致错误。
Apparently it was an issue with the jQuery uiSelect library I was using. It was out of date and causing errors.