2011-07-02 2 views
22

양식을 표시하는 페이지로 돌아가는 게시물에서 리디렉션하면 JQuery 모바일이 양식 대신 결과를 표시합니다.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_to으로 가면 /redirect_to 대신 /thank_you의 내용을 얻습니다. 양식을 새로 고치면 /redirect_to이됩니다.

따라서 redirect_to으로 양식을 보는 대신 thank_you 페이지가 표시됩니다. 여기

는 내가 플라스크, 스냅, 레일, 장고 (내 애플 장고에)에 다시 쓸 것이다이 시점에서, 그것을 이해하지 않는 경우 의 코드시나입니다 ...하지만 읽을만큼 충분히 좋아야합니다. https://gist.github.com/1061639

당신은 기본적으로시나 앱 설치 실행하려면 : gem install sinatra

를 그리고 그것을 실행 ./jquerymobile_redirect_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 
+2

Btw, 코드 예제를 테스트하기가 정말 좋고 쉽습니다. – Heikki

+0

감사! 질문이 "대중적"이 될 때까지 나는 이것을 보지 못했습니다 :-) – igorgue

답변

27

data-url을 지정 여기 (StackOverflow의 내 루비를 감지하지 않기 때문에) Github에서의 코드는 thank_you 페이지. 그러면 양식 제출시 URL이 변경됩니다.

해당 정보는 Redirects and linking to directories에 있습니다.

이것은 또한 후, "/ 계정을"예를 들어, 폼에 "/login.html"을 게시 할 수 있지만 URL에서 페이지를 반환 당신이 리디렉션의 결과로 변경 URL을 반환 할 수 있습니다 성공적인 제출.

+2

이 대답은 저의 한 달을 구했습니다! 감사합니다! 이것에 얽매여있는 다른 사람들에게는 마스터 레이아웃 페이지의 data-url에 request.fullpath의 값을 할당하는 것이 좋습니다. 나를 위해 아마 5 + 버그를 즉시 해결. –