Hi,

After struggling in google  for days on this problem , I hope any of you
could help me solve it.

My problem is that after I submit a form in jquery with $.post to the
server, which is powered by  Django. The post data has been sent to the
server, and saved in the database, but the function of the the ajax success
has not been executed because the page has been flashed.

At the same time, I found a log error in the server:

  File
"/usr/local/lib/python2.6/site-packages/django/core/servers/basehttp.py",
line 279, in run
    self.finish_response()
  File
"/usr/local/lib/python2.6/site-packages/django/core/servers/basehttp.py",
line 318, in finish_response
    self.write(data)
  File
"/usr/local/lib/python2.6/site-packages/django/core/servers/basehttp.py",
line 397, in write
    self.send_headers()
  File
"/usr/local/lib/python2.6/site-packages/django/core/servers/basehttp.py",
line 461, in send_headers
    self.send_preamble()
  File
"/usr/local/lib/python2.6/site-packages/django/core/servers/basehttp.py",
line 379, in send_preamble
    'Date: %s\r\n' % http_date()
  File "/usr/lib/python2.6/socket.py", line 297, in write
    self.flush()
  File "/usr/lib/python2.6/socket.py", line 284, in flush
    self._sock.sendall(buffer)
error: [Errno 32] Broken pipe

So I thought it must be a Django problem; however, my data has been
successfully saved to the database.

Here's the jquery code used:

> $this.submit(function () {
>                 var sentence=$(this).find('input:eq(0)').val();
>                 var translation=$(this).find('input:eq(1)').val();
>                 var keyword=key; //word is a global variable
>                 $.post('addsentence/'+keyword, {
>                     ensent:sentence,
>                     cnsent:translation
>                 },function () {
>                     $('#sentadd').remove();
>                 })
>             })
>

Here I'm going to post the two variable ensent and cnsent to the server.

And my corresponding view on Django is:

> def add_sentence(request,word):
>         example=Example()
>         sentence=request.POST
>         word=Vocabulary.objects.get(word=word)
>         example.word=word
>         example.original=sentence["ensent"]
>         example.translation=sentence["cnsent"]
>         example.user=request.user
>         example.save()
>         return render('noResponse.xml')
>

I thought they were very easy functions, but really out of my understanding
what on earth the problem is! I really need your helps. Thanks in advance.


-- 
Samuel Wu

Reply via email to