0

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

4
  • What do you see when you view source and look at that script tag? I.e. has the 'url' tag resolved to the correct URL? Commented Jul 10, 2011 at 19:03
  • Yes, I used print to print the return contents and when the load() call is made, the console prints out everything correctly, it just won't load for some reason, or do the alert() Commented Jul 10, 2011 at 19:08
  • Are js files processed by django? Commented Jul 10, 2011 at 20:24
  • No, unless you're using an application such as django-compress: code.google.com/p/django-compress. If you were using that, you'd know about it. Commented Jul 10, 2011 at 20:45

2 Answers 2

1

Try wrapping it in a ready:

$(document).ready( function () {
    $('.myClass').load('{% url update_dropdown %}',
        {'kind': "Book" },
        function(data){
            alert(data);
     });    
});
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.