django Jquery ajax request error 404

advertisements

I'm hoping someone can help me here. I can't get make a successful ajax call using django, jquery and the jquery form validation plugin. I'm trying to pass a form email address to a view method to see if it exists in db. But server response is 404 on ajax request. In Firebug i can see the request being sent appears to be formatted properly.

request sent is: http://127.0.0.1:8000/xEmailExists/?email=joeblow%40test.cc

urls.py has: (r'^xEmailExists/(?P\d+)$', 'hwa.website.views.root.xEmailExists'),

and my hwa.website.views.root view file has the following method signature: def xEmailExists(request, email):

I'm using Django 1.1 Bet


That looks like a problem with your URL config. Does accessing that URL interactively (i.e. try navigating to it manually) cause a 404?

There's not really anything magical about URLS for Ajax requests, they're still just URLs - debug them as you would any URL in a Django application.

Unless I'm really sleep-deprived r'^xEmailExists/(?P\d+)$' has a couple of problems:

  1. You're using the named URL pattern without a name - replace ?P with ?P<email>.
  2. You don't want \d+ - that'll match 1 or more digits (i.e. 0-9). You probably want to match all characters for the sake of e-mail validation.
  3. Also, what's the point of passing the e-mail as a query string - why not just do http://127.0.0.1:8000/xEmailExists/joeblow%40test.cc?

Hope that's some help! Apologies if I screwed up the regex matching - it's one of those things I tend to have to fiddle with to get right, and I've not tested my response.