gpt4 book ai didi

redirect - jQuery Mobile 301 重定向问题

转载 作者:行者123 更新时间:2023-12-02 16:36:10 34 4
gpt4 key购买 nike

我正在使用 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 目前无法处理重定向吗?

有什么可能的解决方法吗?

感谢您的帮助。

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

I also posted this problem on the jQuery Mobile forums 。有人建议将 rel="external"添加到 anchor 标记。如果您所做的只是建立一个链接,这在技术上是可行的,但如果您通过其他机制(例如 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 结合使用似乎不起作用。

只是想为关注此问题的其他人提供一些额外的背景信息。

最佳答案

找到了我自己问题的答案。在上面,我提到这会导致使用

标记出现问题。浏览 jQuery Mobile 文档后,我发现了此页面: http://jquerymobile.com/test/docs/forms/forms-sample.html

这里的技巧是,如果您正在制作表单,请强制它不使用 AJAX。您可以通过添加来做到这一点

data-ajax="false"添加到 FORM 标记。

所以这会改变

<form method="post" action="301test.php">

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

只是重申上面所说的内容。如果您需要使用 anchor 链接执行某些操作,只需添加 rel="external"即可。

所以这会改变

<a href="301test.php">301 test</a> 

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

关于redirect - jQuery Mobile 301 重定向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9829224/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com