【问题标题】:Strange cflocation behavior: redirecting to page but not updating url奇怪的 cflocation 行为:重定向到页面但不更新 url
【发布时间】:2014-04-18 04:55:03
【问题描述】:

我在 ColdFusion 中有一个基本的移动登录页面,允许用户输入用户名和密码并登录。成功登录后,页面使用 cflocation 重定向到主页。但是,当页面成功重定向到主页时,它仍然在位置栏中显示登录页面 URL。我们在整个 Web 应用程序中多次使用 cflocation,但我以前从未遇到过这种行为,也无法弄清楚是什么原因造成的。

页面代码要点:

<cfparam name="invalidLogin" default="false">
<cfif cgi.REQUEST_METHOD EQ "POST" AND isDefined("form.email") AND isDefined("form.password") and len(trim(form.email)) and len(trim(form.password))>
    <!--- call the login method --->
    <cfinvoke component="login" method="userlogin" returnvariable="userData">
        <cfinvokeargument name="userName" value="#form.email#">
        <cfinvokeargument name="password" value="#form.password#">
    </cfinvoke>

    <cfif userData.isLoggedIn>
        <cflocation url="index.cfm" addtoken="no">
    </cfif>
    <cfset invalidLogin = true />
</cfif>

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Log In</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="css/jquery.mobile.structure-1.3.2.css" rel="stylesheet" type="text/css" />
        <link href="css/jquery.mobile-1.3.2.css" rel="stylesheet" type="text/css" />
        <link href="css/common.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.3.2.js"></script>
        <script type="text/javascript" src="js/common.js"></script>
    </head>
    <body>
        <div data-role="page" class="bg-color">
            <div class="container">
                <div data-role="content">
                    <div class="article">
                        <div class="logoDiv">
                            <img src="img/companyLogo.png" />
                        </div>
                    </div>

                    <form action="" method="post" name="frmLogin" id="frmLogin" class="margin-top" data-transition="slide">
                        <div>
                            <input type="text" name="email" id="email" placeholder="Username">
                            <input type="password" name="password" id="password" placeholder="Password">
                        </div>
                        <cfif invalidLogin><div>Invalid Login</div></cfif>
                        <div>
                            <input type="submit" value="Log In" data-theme="b" />   
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </body>
</html>

【问题讨论】:

  • 所有设备和移动浏览器都会出现这种情况吗?
  • @Antony - 到目前为止,我只是在我的计算机的网络浏览器上进行测试,我还没有在移动设备上进行测试
  • 可能与 jQM Ajax 导航有关。尝试将data-ajax=false 添加到form
  • 您是否尝试过使用 firebug 来查看 DOM 中发生了什么?
  • @Omar - 修复它,谢谢!如果您将其作为答案发布(有关该属性的文档链接也会有所帮助)我会接受

标签: jquery-mobile redirect coldfusion cflocation


【解决方案1】:

要防止 jQuery Mobile 通过 Ajax 使用 redirect 处理 forms,您需要关闭 Ajax Navigation 并通过 HTTP 处理请求。

为此,请将data-ajax="false" 属性添加到form 标记。这将仅在 form 上停止 Ajax Navigation。

注意,当 Ajax 关闭时,从当前表单页面移动到新页面时,您将失去转换,因此 data-transition="slide" 将不起作用。

<form action="" data-ajax="false" method="post" name="frmLogin" id="frmLogin">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-20
    • 2019-03-09
    • 2017-01-30
    • 2016-05-27
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多