JQuery form submitted in firefox

Please help me with one problem. I have this code for submitting a form via an anchor.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $("#btnLogout").click(function() { $('#frm').submit(); return false; }); }); </script> </head> <body> <form id="frm" action="/" method="post"> <div> <p> <label for="txtLogin">Login:</label> <input name="txtLogin" /> </p> <div> <a id="btnLogout" href="javascript:void(0)"></a> </div> </div> </form> </body> </html> 

It works great on IE7.8, Opera, and Google Chrome, but it doesn't work on FireFox 3.5. I do not understand why this is not working?

+4
source share
5 answers

This could be an FF issue not directly related to jQuery. Try putting the file name in the action attribute as follows:

 <form id="frm" action="/index.html" method="post"> 

Just remember to change index.html to any default document.

-4
source

Based on the answer to the same question: JQuery Form.submit () works in Chrome, but not in Firefox

Add a form object to the DOM before submitting:

 $("#actionform").appendTo("body").submit(); 
+18
source

Accordingly, the jQuery user manual does not work under Firefox when the form was added through Javascript (this means that ajax parsed the material too).

The solution is to clone the form and submit it:

 $('#myform').on('submit', function(e) { e.preventDefault(); if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { $(this).clone().appendTo("body").submit(); // FF only } else { this.submit(); // works under IE and Chrome, but not FF } }); 
+2
source

This works for me:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $("#btnLogout").click(function() { $("#actionform").submit(); return false; }); }); </script> </head> <body> <form id="actionform" action="something.html" method="post" name="forma"> <label for="txtLogin">Login:</label> <input name="txtLogin" /> <a href="#" id="btnLogout">Uno mas</a> </form> </body> </html> 
0
source

Try including the submit button on your form. Even if it is hidden.

 <input type="submit" style="display:none;" /> 
-2
source

Source: https://habr.com/ru/post/1302133/


All Articles