问题:谷歌浏览器的ajax错误
index.html --- POST ---> page1.php --- 链接 ---> page2.html
- “index.html”包含一个
<form>
发布到“page1.php”的内容</li> - “page1.php”包含指向“page2.html”的链接</li>
- “page1.php”包含对“ajax.php”的ajax调用</li>
如何使问题出现?
- 访问“index.html”</li>
- 发布到“page1.php”</li>
- 点击链接到“page2.html”</li>
- 使用后退按钮返回“page1.php”
- 用 F5 重新加载“page1.php”
- 接受重新提交数据
- ajax 错误:ajax 调用失败,错误消息为空
为什么……那东西?
索引.html:
<html>
<head>
</head>
<body>
index
<form method="post" action="page1.php">
<input type="submit">
</form>
</body>
</html>
page1.php:
<html>
<head>
<script src="jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function call_ajax()
{
$.ajax
(
{
type: "POST",
url: "ajax.php",
success: function( response )
{
console.log( response );
},
error: function (xhr, ajaxOptions, thrownError)
{
console.log( '%o', xhr );
console.log( '%o', xhr.responseText );
console.log( '%o', thrownError );
}
}
);
}
$( document ).ready(function() {
call_ajax();
});
</script>
</head>
<body>
page 1
<a href="page2.html">page2</a>
</body>
</html>
page2.html:
<html>
<head>
</head>
<body>
page 2
<a href="javascript:history.back()">back</a>
</body>
</html>
ajax.php:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('error_reporting', E_ALL);
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');
$r = array( 'message' => 'one two one two, this is a test' );
echo json_encode( $r );
?>