形式方法”;POST”;不在firefox工作

Form method "POST" not working in firefox

本文关键字:工作 firefox POST 形式方法 不在      更新时间:2023-09-26

以下代码适用于Chrome 47.0.2526.73版本,但在Firefox和IE 11上不起作用。知道的原因吗

HTML:

<form action="@Url.Content("~/Account/LogOn/")" method="post" id="login_form">
     <input type="text" id="username" name="username" placeholder="Username" value=""/>
     <input type="password" id="password" name="password" placeholder="Password" value=""/>
     <button id="btnLogin" class="btn btn-inverse pull-right" type="submit" onclick="OpenPage()">Sign In</button>
</form>

JAVASCRIPT

function OpenPage() {
    $('body').empty().load('../../../Content/LoaderHtml/loader.html');
    return false;
}

代码必须从MVC调用ActionResult方法。

编辑:只有onclick事件在Firefox和IE中被触发(在Chrome中,该形式也会触发Controller的方法),如果我删除onclick,那么在Firefox、IE和Chrome 中一切都很好

编辑2:我需要触发onclick事件,并将表单发布到服务器(Chrome的行为还可以,但我如何才能在firefox和IE中实现这一点)。

谢谢你的帮助!

表单包含submit按钮开关是调用javascript开关是阻止表单提交。

 <button onclick="OpenPage()">Sign In</button>

关于你的问题

以下代码适用于Chrome 47.0.2526.73版本,但适用于FirefoxIE 11不起作用。

调用了onclick,但未返回内联使用的。从OpenPage函数返回false的那一刻起,正确的格式必须是onclick="return OpenPage()",然后在所有浏览器上都有相同的响应,表单将不会提交。

为什么一个浏览器的行为与其他浏览器不同,可能是因为这个原因,也可能是其他javascript错误。

如何提交

在javascript调用上设置return true;,并设置onclick="return OpenPage()"