【发布时间】:2012-04-07 10:10:50
【问题描述】:
我将 jQuery 1.6.4 与 jQuery Mobile 1.0.1 一起使用。每当您链接到然后尝试执行 301 重定向的页面时,我都会遇到问题。
我已经设置了一个示例页面:http://www.widgetsandburritos.com/jquery-mobile-test/
此页面上唯一的内容是 jQuery Mobile 包含和指向另一个页面的链接,该页面在其他地方有 301 重定向。
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<a href="301test.php">301 test</a>
</body>
</html>
301test.php 有以下内容:
<?php
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: 301success.html" );
?>
这应该只是简单地将浏览器传递给 301success.html。如果你直接去那个 URL 就可以了
http://www.widgetsandburritos.com/jquery-mobile-test/301test.php
但是,当您使用 jQuery Mobile 从页面单击链接时,它会显示“未定义”。 jQuery Mobile 目前是否无法处理重定向?
任何可能的解决方法?
感谢您的帮助。
编辑 [2012 年 3 月 23 日上午 12:41 CST]
I also posted this problem on the jQuery Mobile forums。那里有人建议将 rel="external" 添加到锚标记。如果您所做的只是建立链接,这在技术上是可行的,但如果您通过其他机制(例如 POST 请求)进行重定向,则无法解决问题。
为了说明,我在http://www.widgetsandburritos.com/jquery-mobile-test/test2.html 设置了一个辅助测试
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<form method="post" action="301test.php">
<input type="submit" value="test" />
</form>
</body>
</html>
不是从链接到达 301test.php 重定向页面,而是现在我们提交的表单的位置。这将被使用的上下文是这样的,如果您提交一个有错误的表单,它将保持在同一页面上,以便您更正错误。如果没有错误,它会将您重定向到成功页面。这样做是为了避免在用户刷新浏览器时再次提交表单。它在普通的 Web 应用程序中运行良好。但在与 jQuery Mobile 组合时,它似乎不起作用。
只是想我会为关注此问题的其他人提供一些额外的背景信息。
【问题讨论】:
标签: redirect jquery-mobile http-status-code-301