I’m trying to enter a word and have it show up on page through ajax. There something simple I’m missing…
So I’m sending the info like this with Jquery:
$.ajax({
url: url,
type:"POST",
data:{'word': word},
success: function(data){
//do something
}
});
and the information is getting into the view and saving into the DB. The problem happens when I try to return the new word:
def add_word(request, lecture_id):
l = get_object_or_404(Lecture, pk=lecture_id)
if request.method == "POST":
#see if there is a value with p
if request.POST.has_key('word') and request.POST['word'] != "":
success = {}
try:
oldWord = l.post_set.get(word=request.POST['word'])
except:
newWord = l.post_set.create(word=request.POST['word'], count = 1)
success = {'new': str(newWord.word), 'count': str(newWord.count)}
else:
oldWord.count += 1
oldWord.save()
success = {'old': str(oldWord.word), 'count': str(oldWord.count)}
return HttpResponse(json.dumps(success), mimetype="application/javascript")
return HttpResponse(reverse('post.views.lecture_display', args=(l.id,)))
Im getting a 500 error…
[13/Oct/2011 15:14:48] "POST /lecture/3/add HTTP/1.1" 500 66975
Without seeing the traceback, my guess is that what’s failing is [one of]:
Open the URL directly in your browser, and you’ll get the default Django traceback, 500 view.