jQuery Mobile 301重定向问题

前端之家收集整理的这篇文章主要介绍了jQuery Mobile 301重定向问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用jQuery 1.6.4与jQuery Mobile 1.0.1.当我们链接到一个页面然后尝试做一个301重定向时,我遇到一个问题.

我已经设置了一个示例页面http://www.widgetsandburritos.com/jquery-mobile-test/

这个页面上唯一的一件事就是jQuery Mobile包含了一个链接到另一个页面,其中有一个301重定向在别的地方.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
  5. <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
  6. <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
  7. </head>
  8. <body>
  9. <a href="301test.PHP">301 test</a>
  10. </body>
  11. </html>

301test.PHP具有以下内容

  1. <?PHP
  2. header( "HTTP/1.1 301 Moved Permanently" );
  3. header( "Location: 301success.html" );
  4. ?>

这只是简单地将浏览器传递给301success.html.如果您直接访问该网址,它将起作用

http://www.widgetsandburritos.com/jquery-mobile-test/301test.php

但是当您使用jQuery Mobile单击页面上的链接时,它会显示“undefined”. jQuery Mobile目前无法处理重定向吗?

任何可能的工作?

谢谢你的帮助.

编辑[3/23/12 12:41 AM CST]

有人建议在锚标签添加rel =“external”.在技​​术上,如果您正在做的是创建链接,但如果您通过其他机制(如POST请求)进行重定向,则无法解决问题.

为了说明,我已经在http://www.widgetsandburritos.com/jquery-mobile-test/test2.html设置了二次测试

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
  5. <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
  6. <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
  7. </head>
  8. <body>
  9.  
  10. <form method="post" action="301test.PHP">
  11. <input type="submit" value="test" />
  12. </form>
  13.  
  14. </body>
  15. </html>

而不是从链接到达301test.PHP重定向页面,现在是我们提交的表单的位置.将使用的上下文将是这样的,如果您提交一个错误的表单,它将保留在同一页面上,允许您更正错误.如果没有错误,它将重定向到成功页面.这样做是为了避免在用户刷新浏览器时再次提交表单.它在正常的Web应用程序中非常出色.但是在与jQuery Mobile的组合中似乎不起作用.

只是以为我会给这个问题后的其他任何人提供一些额外的上下文.

解决方法

弄清楚我自己的问题的答案.在上文中,我提到这是使用< form>标签.浏览jQuery Mobile文档后,我发现这个页面http://jquerymobile.com/test/docs/forms/forms-sample.html

这里的诀窍是如果你正在做一个表单,强制它不要使用AJAX.你通过添加来做到这一点

data-ajax =“false”到FORM标签.

所以这个变化

  1. <form method="post" action="301test.PHP">

  1. <form method="post" action="301test.PHP" data-ajax="false">

只是重申上面所说的话.如果您需要使用锚点链接进行某些操作,只需添加rel =“external”即可.

所以这个变化

  1. <a href="301test.PHP">301 test</a>

  1. <a href="301test.PHP" rel="external">301 test</a>

猜你在找的jQuery相关文章