jQuery .load()在Django中不起作用 [英] jQuery .load() not working in Django

查看:1199
本文介绍了jQuery .load()在Django中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Django中调用一个url并加载其内容。现在我有:

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>

然后update_dropdown引用的视图是:

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))

但是,由于某种原因,.load()将无法正常工作。如果我直接访问URL,它会显示我期望的数据,但是.load()不会合作。我知道这不是一个显示问题,因为警报将不起作用(除非我删除了@csrf_exempt,那么它会提醒错误页面的HTML)

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 .

我可以得到它如果我返回类型为JSON对象并使用getJSON(),但是我不希望

I can get it to work if I make the return type a JSON object and use getJSON(), but I'd prefer not to

推荐答案

显然这是我正在使用的jQuery uiSelect库的一个问题。它已经过时,导致错误。

Apparently it was an issue with the jQuery uiSelect library I was using. It was out of date and causing errors.

这篇关于jQuery .load()在Django中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆