问题:google chrome的ajax错误
index.html --- POST ---> page1.php --- link ---> page2.html
<form>
如何解决问题?
为什么......那件事?
index.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 );
?>
答案 0 :(得分:0)
可能是服务器/浏览器的配置有问题吗?
我尝试使用PHP通过fastcgi和运行Chromium版本30.0.1553.0(209444)在本地安装的lighttpd中创建与上述完全相同的代码来确认您的问题,但无法重现您的问题。< / p>
在查看控制台时,无论是使用index.html访问page1.php还是使用“返回”链接访问page2.html并使用F5刷新,日志始终会显示正确的输出。
Object {message: "one two one two, this is a test"}