views:

322

answers:

4

Hello all. Please, help me with one problem. I have this code, for submitting form via anchor.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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 fine on IE7,8, Opera and Google Chrome, but does not work on FireFox 3.5. I can not understand why it does not work? Thank You!

A: 

This may be a FF issue not related to jQuery directly. Try putting a filename in the action attribute like this:

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

Just make sure to change index.html to whatever your default document is.

palehorse
this solution does not work to :(
msi
Odd, it worked for me. What is the actual file name that you are trying to post to?
palehorse
@palehorse I'm using ASP.NET MVC, so the actual is action method of some controller (the URL for action form method is "/Security/Logout"). But actin method does not go to this action, I've tried it via debugger.
msi
Does your routing table include a /default.aspx or something like that? If so, perhaps you could code the form rather than using a form helper to put the action in. You may also be able to add something to the routing table that will accept a /index.htm or some other default document name in order to do this.
palehorse
That's not an ASP.NET MVC problem, this is a FireFox problem, because all works fine on IE, Opera and Google Chrome
msi
I understand that it's a FireFox problem; however, sometimes to solve a problem with one technology we need to use another in a slightly different way. I've used jQuery's submit() method with MVC many times, but there's always been more than just a / in the action, that's why I suggest setting it up to use either a "file" name/route or something like that, anything to get away from the single "/" in the action.
palehorse
it's very strange, but when I tried to use action without slash (/):<form id="frm" action="index.html" method="post">submit works fine.Why?
msi
It sounds like it could be a bug in FireFox. There's another bug dealing with a form that has an action beginning with a / that doesn't submit when "Enter" is pressed. It could be a related bug with slightly different behavior.
palehorse
A: 

I've copied your code and just change the script src line and it works. Ensure you're including it correctly.

Btw, jQuery Library is currently on v1.4.2.

Keyne
I'll try to use jQuery 1.4.1 but only after 3 hours :)
msi
@Keyne this should be a comment rather than an answer ..
c0mrade
Sorry @c0mrade, next time I do that.
Keyne
@Keyne no problem we're all suggesting things once in a while ..
c0mrade
Actually, latest release is 1.4.2: http://blog.jquery.com/2010/02/19/jquery-142-released/
Jasper De Bruijn
@Jasper I change it, thanks!
Keyne
A: 

Try to include a submit button in your form. Even if it is hidden.

<input type="submit" style="display:none;" />
Rexxars
@Rexxars That makes no sense at all..
c0mrade
@c0mrade are right
msi
A: 

This works for me :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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>
c0mrade
this works for me too.But, when you'll try to use "/" before something.html, like this<form id="actionform" action="/something.html" method="post" name="forma">it'll not work only on FireFox :(
msi
@msi why would you use /something.html instead of something ?
c0mrade
because I need to have access to this file from site root.And when I have site structure like this:/test/foo.htmlindex.htmlsomthing.htmlI'll not have an access to the somthing.html form /test/foo.html
msi
@msi of course you need to deploy it to some web server first ..
c0mrade
@c0mrade But on IE and Chrome all works fine. This is realy bug (or some security feature) in FireFox
msi