我正在通过点击按钮逐步更改我的jQuery移动应用程序中的页面。这是我正在使用的代码:
$("#paymentConfrim").click(function() {
$( ".paymentDetailForm" ).submit(function( event ) {
if(!validatePaymentDetailForm()){ // if false comes from validation
return false;
}
else{
// I'm using changePage instead of jQuery pagecontainer widget as I'm using older version of jQuery mobile
$.mobile.changePage( "#submissionConfirmation", {} );
return true;
}
});
页面已成功更改,但在一秒钟或几分之一秒后,应用程序将返回主页。由于应用程序很大,有很多遗留代码,我无法确定导致该页面更改的代码。因为它发生在几毫秒之后,我怀疑有一些setTimeOut
函数导致了这种情况。
奇怪的是,虽然该网页已更改为主页,但网址仍与#submissionConfirmation
页面相同,即localhost/mypage.html#submissionConfirmation
如何调试并确切知道导致重定向的JavaScript代码?
答案 0 :(得分:0)
重新加载是由提交的表单引起的。您需要通过调用protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
if (!Request.IsAuthenticated) return;
using (var db = new SecurityRoleEntities())
{
var user = User as ClaimsPrincipal;
var userEntry = db.Users.FirstOrDefault(x => x.IdSid.ToLower().Equals(user.Identity.Name.ToLower()));
var roles = FindRolesByUser(userEntry);
if(roles == null) return;
foreach (var role in roles)
{
var id = new ClaimsIdentity();
id.AddClaim(new Claim(ClaimTypes.Role, role.Name));
ClaimsPrincipal.Current.AddIdentity(id);
}
}
}
作为处理程序中的第一件事来阻止默认表单提交行为。
event.preventDefault()