[Fixed]-Why doesn't the following jquery code work?

1👍

You should use the browser tools, where your error shows, to see the traceback coming from the server. What that would have told you is that you can’t pass a queryset directly to JsonResponse; you need to serialize it properly.

However that doesn’t actually seem to be what you want to do. You don’t care about the data, you just care about whether there is a match. So you should pass the result of .exists() on that queryset, which will give you a boolean:

data = {
  'is_taken' : Users.objects.filter(username__iexact=username).exists()
}

Leave a comment