ajaxSubmit doesn't submit with Firefox, submits with refresh in explorer
This has been driving me insane for days, sure would appreciate any ideas:
I'm using a very basic implementation of ajaxSubmit for a form which only needs to post, but gets trickier as it is handled by a cgi script, which I know almost nothing about.
Everything works perfectly - the form is submitted and the textarea updates with the confirm message - in Chrome and Safari. Explorer does the submit, but refreshes the page. Firefox displays the confirmation message but doesn't appear to actually submit the form, as does Opera - which I'm quickly starting to not care about, haha - but of course I simply must support Firefox.
formSubmit.js
- $(function() {
- $("form#chatIn").submit(function() {
- $("form#chatIn").ajaxSubmit();
- $("textarea#Message").val('MESSAGE SENT').fadeIn('slow').click(function () {
- $(this).val('');
- });
- return false;
- });
- });
HTML
- <form id="chatIn" name="chatInForm" action="http://path/to/post.cgi" method="post">
- <fieldset>
- <textarea name="Message" id="Message" rows="2" cols="10" onfocus="this.value=''; this.onfocus=null;">Your message to the Lounge Hotline!</textarea>
- <input style="position:relative; top: -10px;" type="submit" name="submitButton" title="Send!" value="|| Send ||" />
- </fieldset>
- </form>
post.cgi
- #!/usr/bin/python
-
- import cgi, urllib2, urllib
- import cgitb
- cgitb.enable()
- import os
-
-
- # This file needs to be readable and writable from this cgi
- file_name = "my_url"
-
- form = cgi.FieldStorage()
-
- # Set the URL of your form [anyone know how to get it to return to whatever page we came from?]
- url = "http://thePageThatStraightHTMLformWouldReturnTo.com/"
-
- # If we haven't a Message or URL let the user know it and redirect to the form
- if "Message" not in form and "URL" not in form:
-
- print "Content-Type: text/html"
- print
- print "<html><head><meta http-equiv="refresh" content="5; URL=%s"></head>" %url
- print "<body style="text-align: center; margin-top: 20px;">"
- print "Please fill in the message field.<br><a href="%s">Redirection to the form in 5 seconds</a>" %url
- print "</body></html>"
-
- # If we have URL param then this is an URL update
- elif "URL" in form:
- # Intercept errors
- try:
- # Write the url to the file, overwriting the existing file.
- f = open(file_name,'w')
- f.write(form["URL"].value)
-
- # Let the caller know it worked.
- print "Content-Type: text/html"
- print
- print "OK"
- except:
- # it has an error.
- print "Content-Type: text/html"
- print
- print "ERROR|%s" %file_name
-
- # We have Message then this is a status update.
- else:
- # Redirect back to the form
- print "Status: 302 Moved"
- print "Location: %s" %url
- print
-
- # Read in the url from the file
- f = open(file_name,'r')
- base_url = f.read()
-
- # Build the complete url with query args.
- message = form["Message"].value
- args = "?Message=%s" % urllib.quote(message)
-
- # Make the request, giving the status to the script.
- response = urllib2.urlopen(base_url + args)