Your JS looks decidedly incorrect. You say the aim is to prevent the form being submitted in certain scenarios, yet your form submit handler neither returns true nor false. You return truthiness from your anonymous AJAX handler, but that is not the same.
Secondly, your check to see whether to submit the form uses AJAX. The first A is important there, the communication happens asynchronously. This sequence of events occurs: Form submit handler called Form submit handler creates an AJAX request AJAX request is submitted to the server Form submit handler completes with no return value Browser prepares to submit the form Browser closes any open network connections the page has Server attempts to write to closed socket, generating quoted exception Browser submits form to server You need to make your jquery AJAX call synchronous, and return true/false from the appropriate location. "jquery synchronous ajax" should give you all the information you need. Cheers Tom On Wed, Aug 22, 2012 at 10:56 AM, mapapage <[email protected]> wrote: > Hi!I'm trying to perform an ajax call on the submit of a form. The form will > be submitted depending on the call's result. > I'm doing sth like that: > > $("#myform").submit(function() { > var rdatefrom=$('#id_rdatefrom').val(); > var arr_sdateText = rdatefrom.split("/"); > startday = arr_sdateText[0]; > startmonth = arr_sdateText[1]; > startyear = arr_sdateText[2]; > > $.get(""+startday+"/"+startmonth+"/"+startyear+"/")function(data) { > msg=data.msg; > if(msg!=='None'){ > alert(msg); > return false;} > return true; > }); > }); > but the form is being submitted regardless the call's result while I get the > monstrous: > > Traceback (most recent call last): > File "/usr/lib/python2.6/wsgiref/handlers.py", line 94, in run > self.finish_response() > File "/usr/lib/python2.6/wsgiref/handlers.py", line 135, in > finish_response > self.write(data) > File "/usr/lib/python2.6/wsgiref/handlers.py", line 218, in write > self.send_headers() > File "/usr/lib/python2.6/wsgiref/handlers.py", line 274, in send_headers > self.send_preamble() > File "/usr/lib/python2.6/wsgiref/handlers.py", line 200, in send_preamble > 'Date: %s\r\n' % format_date_time(time.time()) > File "/usr/lib/python2.6/socket.py", line 300, in write > self.flush() > File "/usr/lib/python2.6/socket.py", line 286, in flush > self._sock.sendall(buffer) > error: [Errno 32] Broken pipe > > What's going on? > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/7G1wG2673jQJ. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

