Jquery mobile JQuery Mobile中的重定向错误

Jquery mobile JQuery Mobile中的重定向错误,jquery-mobile,Jquery Mobile,当我在返回显示表单的页面的帖子中重定向时,JQuery mobile会显示结果,而不是表单 假设我有三个资源: / => Just shows a link to the /redirect_to resource, this is to test /redirect_to => GET: Shows a form to say your name in /thank_you /redirect_to => POST: Just redirects to /thank_you

当我在返回显示表单的页面的帖子中重定向时,JQuery mobile会显示结果,而不是表单

假设我有三个资源:

/ => Just shows a link to the /redirect_to resource, this is to test
/redirect_to => GET: Shows a form to say your name in /thank_you
/redirect_to => POST: Just redirects to /thank_you showing the name that you input
/thank_you => GET: Shows a text "Thank you name!"
在我到达终点后,谢谢你!页面,如果我尝试返回主页,然后转到
/redirect\u to
我会得到
/thanky\u you
的内容,而不是
/redirect\u to
,如果我刷新页面,我会得到表单

因此,我看到的不是
重定向到
的表单,而是
谢谢
页面

这是Sinatra中的代码,如果您不理解,现在我将在Flask、Snap、Rails、Django中重新编写(我的应用程序在Django上)。。。但它应该足够好读。以下是Github上的代码(因为StackOverflow没有检测到我的ruby):

要运行应用程序,基本上需要安装sinatra:
gem安装sinatra

然后运行它:
/jquerymobile\u redirect\u error.rb

#!/usr/bin/env ruby

require 'rubygems'
require 'sinatra'

get '/' do
  <<-end_page
<!DOCTYPE html> 
<html> 
  <head> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
  </head>
  <body>
    <div data-role="page">
      <div data-role="header" data-position="fixed">
        <h1>JQuery Error</h1>
        <a href="/" data-icon="home">Home</a>
        <a href="/" data-icon="delete">Logout</a>
      </div><!-- /header -->

      <div data-role="content">
        <h1>Go to /redirect_to <a href="/redirect_to">here</a>.
      </div><!-- /content -->

      <div data-role="footer" data-position="fixed">
        <h1>Footer</h1>
      </div><!-- /footer -->
    </div><!-- /page -->
  </body>
</html>
  end_page
end

get '/redirect_to' do
  <<-end_page
<!DOCTYPE html> 
<html> 
  <head> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
  </head>
  <body>
    <div data-role="page">
      <div data-role="header" data-position="fixed">
        <h1>JQuery Error</h1>
        <a href="/" data-icon="home">Home</a>
        <a href="/" data-icon="delete">Logout</a>
      </div><!-- /header -->

      <div data-role="content">
        <form action="/redirect_to" method="post" accept-charset="utf-8">
          <p><label for="name">Name</label><input type="text" id="name" name="name" value="" id="name" placeholder="input your name">
          <p><input type="submit" value="Redirect to /thank_you &rarr;"></p>
        </form>
      </div><!-- /content -->

      <div data-role="footer" data-position="fixed">
        <h1>Footer</h1>
      </div><!-- /footer -->
    </div><!-- /page -->
  </body>
</html>
  end_page
end

post '/redirect_to' do
  redirect "/thank_you/#{params[:name]}"
end

get '/thank_you/:name' do |name|
  <<-end_page
<!DOCTYPE html> 
<html> 
  <head> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
  </head>
  <body>
    <div data-role="page">
      <div data-role="header" data-position="fixed">
        <h1>JQuery Error</h1>
        <a href="/" data-icon="home">Home</a>
        <a href="/" data-icon="delete">Logout</a>
      </div><!-- /header -->

      <div data-role="content">
        <h1>Thanks #{name}!</h1>
      </div><!-- /content -->

      <div data-role="footer" data-position="fixed">
        <h1>Footer</h1>
      </div><!-- /footer -->
    </div><!-- /page -->
  </body>
</html>
  end_page
end
#/usr/bin/env ruby
需要“rubygems”
需要“sinatra”
获取“/”do
页脚
结束页
结束
获取“/redirect_to”do
页脚
结束页
结束
post'/redirect_to'do
重定向“/谢谢/{params[:name]}”
结束
获取“/thank_you/:name”do | name|
页脚
结束页
结束

为您的感谢页面指定
数据url
。这将强制更改表单提交时的url

<div data-role="page" data-url="/thank_you">

我从下面的文档中找到了这些信息

这还允许您返回因重定向而更改的url,例如,您可以将表单发布到“/login.html”,但在成功提交后从url“/account”返回页面


顺便说一句,非常好的,易于测试的代码示例。谢谢!直到这个问题变得“流行”我才意识到这一点:-)这个答案救了我整整一个月,谢谢!对于其他可能被困在这个问题上的人来说,通常最好将request.fullpath的值指定给主布局页面上的数据url(如果有的话)。对我来说,它可能一次解决了5个以上的bug。