2009/2/10 min <inuyasha...@gmail.com>: > > Hi, everyone. > > I have a question for the following example. > > Firstly, in the view.py: > > def test_1(request, zipcode, pro): > if zipcode == 'a' and pro == 'b': > city = 'c' > else: > city = '' > > return HttpResponse(city) > > def test_0(request): > return render_to_response('test_0.html', {}) > ------------------------------------------------------------------------------------- > Then, in the test_0.html > > <html> > <html> > <head> > <title>Register form</title> > <script src="/site_media/jquery.js" type="text/javascript"></script> > <script type="text/javascript"> > function getZipData() { > var zipcode = $('#zip').val(); > var pro = $('#pro').val(); > $.get('http://127.0.0.1/ajax/test_1/' + zipcode + '&' + pro + > '/' , function(data) { > $('#city').attr({'value':data}); > }); > } > </script> > </head> > <body> > <table> > <form actioon="" method="post"> > <tr><td>Pro:</td><td><input id="pro" type="text" name="pro"/></tr> > <tr><td>Zip:</td><td><input id="zip" type="text" name="zip"/></tr> > <tr><td>City:</td><td><input id="city" type="text" name="city"/></tr> > <input type="button" value="done" onclick="getZipData()" /> > </form> > </table> > </body> > > -------------------------------------------------------------------------- > In the urls.py > > (r'^ajax/test_0/$', test_0), > (r'^ajax/test_1/(\S+)/$', test_1), > --------------------------------------------------------------------------- > When I input b to the Pro inputbox and a to the Zip inputbox, and > click the done button, the firebug displays :500 Interserver Error > > I think there are some problem with the $.get('http://127.0.0.1/ajax/ > test_1/' + zipcode + '&' + pro + '/' , function(data) {$('#city').attr > ({'value':data}); }); OR > > def test_1(request, zipcode, pro): > if zipcode == 'a' and pro == 'b': > city = 'c' > else: > city = '' > > return HttpResponse(city) > > Could you please give me some idea? > Test your Ajax URL agains the view directly with the browser. It's seems there is some kind of problem there. view: def test_1(request, zipcode, pro): url (r'^ajax/test_1/(\S+)/$', test_1) At firsth sight they don't match with http://127.0.0.1/ajax/test_1/' + zipcode + '&' + pro +"/"
Try: url = r'^ajax/test_1/(?P<zipcode>\w+)/(?P<pro>\w+)/$ ... and http://127.0.0.1/ajax/test_1/' + zipcode + '/' + pro +"/" Hope it helps! -- Antoni Aloy López Blog: http://trespams.com Site: http://apsl.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---