我有一个用户输入用户名和密码的登录表单。当他们点击一个图像按钮来提交我做一个Ajax调用来验证用户。该响应返回目标网址。现在,当我尝试做一个“window.location.href = url”的过程不适用于FireFox 7(FF),但它可以在其他浏览器IE,Chrome ...等工作window.location.href和JQuery不在FF 7中工作
这是我的jquery ajax调用。
var loginSubmit = function() {
if ($('#loginForm').data('isSubmitting')) return false;
showProgress('Logging in..');
$('#loginErrors').empty();
$('#login-form').fadeTo(100, 0.4);
$.ajax({
cache: false,
url: '/dispatcher/user/login',
data: {
'user': $('#userName').val(),
'pwd': $('#password').val(),
'continuePath': $('#continuePath').length > 0 ? $('#continuePath').val() : '/my-account'
},
type: 'POST',
success: function (data) {
$('#loginForm').data('isSubmitting', true);
console.log("Data from Controller: " + data.dest);
if (data.dest) {
var href = data.dest;
window.location.href = href;
return false;
} else {
console.log("DATA DEST FALSE");
$('#loginForm').data('isSubmitting', false);
$('#login-form').fadeTo(100, 1);
showError('Invalid username/password');
}
}
});
return false;
};
$('#loginForm').submit(loginSubmit);
这是我的表格。
<form id="loginForm" action="#">
<c:if test="${sessionScope['continuePath'] != null}">
<input type="hidden" name="continuePath" value="${sessionScope['continuePath']}"/>
</c:if>
<div id="progressMessage" style="color: #333; font-weight: bold;"></div>
<div id="loginErrors" style="color: red; font-weight: bold"></div>
<div id="login-form">
<dl>
<dt><label for="userName">Email Address:</label></dt>
<dd><input name="user" id="userName" type="text" size="30" maxlength="80"/></dd>
<dt><label for="password">Password:</label></dt>
<dd><input name="pwd" id="password" type="password" /></dd>
</dl>
<div class="login_button">
<input type="image" src="/assets/images/user/btn-log-in.gif" alt="Login"/>
<br/><br/>
<a href="javascript:openPopup('forgotPassword');" class="default">Forgot your password?</a>
<!--
<a href="#" rel="#forgotPasswordDialog" class="default">Forgot your password?</a>
-->
</div>
</div>
</form>
为什么这种行为在Firefox 7有什么不同?有人可以提出一个可以在所有浏览器中工作的解决方案吗?你能感觉到我的沮丧吗?
是否只用'location.href =网址工作;'? –
如果在作用域链上存在某个中间变量对象的* window *属性和no * location *属性,那么这只会有所作为。这是偶然的机会,所以我猜想值得一试。 * window.location *和* location *都可以预期通常解析为相同的对象,即[window.location](http://www.w3.org/TR/html5/history.html#the-location - 接口)对象,在大多数情况下。当然不能保证,这就是为什么许多脚本保持对全局对象的独立引用,这可以用来保证访问预期的对象。 – RobG
我试过window.location,位置和window.location.href在FF7上没有成功,所有其他工作正常。 – Byron